shadabahmed / logstasher

Awesome rails logs
MIT License
817 stars 136 forks source link

Logging after action has been processed. #144

Open braindeaf opened 6 years ago

braindeaf commented 6 years ago

It would appear according to lib/logstasher/rails_ext/action_controller/metal/instrumentation.rb That the two locations where the payload is appended to occur before the action is processed. Can you clarify how they then differ from one another.

The downside to this is that something that occurs within the action cannot be appended to the log, e.g. logging a user in, or the changed state of an order, etc. Shouldn't :logstasher_add_custom_fields_to_payload be after the process_action?

` if self.respond_to?(:logstasher_add_custom_fields_to_request_context) logstasher_add_custom_fields_to_request_context(LogStasher.request_context) end

    if self.respond_to?(:logstasher_add_custom_fields_to_payload)
      before_keys = raw_payload.keys.clone
      logstasher_add_custom_fields_to_payload(raw_payload)
      after_keys = raw_payload.keys
      # Store all extra keys added to payload hash in payload itself. This is a thread safe way
      LogStasher::CustomFields.add(*(after_keys - before_keys))
    end

    result = super

`

Also the method call 'append_info_to_payload(payload)' after the request has been processed seems to duplicate the same logic which is confusing.

Can you clarify?