actindi / act-fluent-logger-rails

Fluent logger
MIT License
118 stars 72 forks source link

Logging request params #20

Closed diclophis closed 9 years ago

diclophis commented 9 years ago

Does this gem include request params in the structured log entry sent to fluentd?

quek commented 9 years ago

By default, the params will be output as a string in the messages.

http://example.com/?a=b&c[d]=e&c[f]=g

2015-09-12T11:58:45+09:00 outing  {"messages":["Started GET \"/?a=b&c[d]=e&c[f]=g\" for 127.0.0.1 at 2015-09-12 11:58:43 +0900","Processing by TopController#index as HTML","  Parameters: {\"a\"=>\"b\", \"c\"=>{\"d\"=>\"e\", \"f\"=>\"g\"}}","Completed 200 OK in 2083ms (Views: 1596.7ms | ActiveRecord: 238.7ms | Solr: 19.4ms)"],"level":"INFO"}

By setting as follows, it will be able to output the params as json.

config.logger = ActFluentLoggerRails::Logger.new(log_tags: {
  params: ->(request) { request.params }
})
2015-09-12T11:58:45+09:00 outing  {"messages":["Started GET \"/?a=b&c[d]=e&c[f]=g\" for 127.0.0.1 at 2015-09-12 11:58:43 +0900","Processing by TopController#index as HTML","  Parameters: {\"a\"=>\"b\", \"c\"=>{\"d\"=>\"e\", \"f\"=>\"g\"}}","Completed 200 OK in 2083ms (Views: 1596.7ms | ActiveRecord: 238.7ms | Solr: 19.4ms)"],"level":"INFO","params":{"a":"b","c":{"d":"e","f":"g"},"controller":"top","action":"index"}}
diclophis commented 9 years ago

Great thanks!

zedtux commented 7 years ago

@quek it seems to no more work, request.params is always empty for me while I should have 2 params. I'm with latest version of all and Rails 4.

quek commented 7 years ago

I make sample project. https://github.com/quek/act-fluent-logger-rails-issue-20 It seems to work...

zedtux commented 7 years ago

Thank you @quek. I will try the configuration from your project and let you know.

In the other hand, I was able to make it working but in the lograge gem with the following:

  # Fluentd -> ElasticSearch -> Kibana logging
  config.log_level = :debug
  config.logger = ActFluentLoggerRails::Logger.new(log_tags: {
                    host: ->(request) do
                      request.host
                    end
                  })
  config.lograge.enabled = true
  config.lograge.custom_options = lambda do |event|
    exceptions = %w(controller action format)
    {
      params: event.payload[:params].except(*exceptions)
    }
  end
  config.lograge.formatter = Lograge::Formatters::Json.new

This is working fine.

With ActFluentLoggerRails I tried to add the hostname, and it is working, but is out of the messages key in the JSON so Fluentd is not taking it into account.

zedtux commented 7 years ago

@quek I think the issue is a misunderstanding from my side. When I'm talking about params, I'm referring to the params object in Rails from a controller, which includes the params you're pointing, but also the params from the URL.

In the URL /admin/applications/4/edit, params will includes {id: 4}.

With the configuration form my previous comment, it is working as I am expecting.