README.md in lograge-0.2.0 vs README.md in lograge-0.2.1

- old
+ new

@@ -68,23 +68,51 @@ # custom_options can be a lambda or hash # if it's a lambda then it must return a hash config.lograge.custom_options = lambda do |event| # capture some specific timing values you are interested in - {:name => "value", :timing => some_float.round(2)} + {:name => "value", :timing => some_float.round(2), :host => event.payload[:host]} end end ``` +You can then add custom variables to the event to be used in custom_options + +```ruby +# app/controllers/application_controller.rb +class ApplicationController < ActionController::Base + def append_info_to_payload(payload) + super + payload[:host] = request.host + end +end +``` + +To further clean up your logging, you can also tell Lograge to skip log messages +meeting given criteria. You can skip log messages generated from certain controller +actions, or you can write a custom handler to skip messages based on data in the log event: + +```ruby +# config/environments/production.rb +MyApp::Application.configure do + config.lograge.enabled = true + + config.lograge.ignore_actions = ['home#index', 'aController#anAction'] + config.lograge.ignore_custom = lambda do |event| + # return true here if you want to ignore based on the event + end +end +``` + Lograge supports multiple output formats. The most common is the default -lograge format described above. Alternatively, you can also generate JSON -logs in the json_event format used by [Logstash](http://logstash.net/). +lograge key-value format described above. Alternatively, you can also generate +JSON logs in the json_event format used by [Logstash](http://logstash.net/). ```ruby # config/environments/production.rb MyApp::Application.configure do - config.lograge.log_format = :logstash + config.lograge.formatter = Lograge::Formatters::Logstash.new end ``` *Note:* When using the logstash output, you need to add the additional gem `logstash-event`. You can simply add it to your Gemfile like this @@ -92,9 +120,29 @@ ```ruby gem "logstash-event" ``` Done. + +The available formatters are: + +```ruby + Lograge::Formatters::Cee.new + Lograge::Formatters::Graylog2.new + Lograge::Formatters::KeyValue.new # default lograge format + Lograge::Formatters::Logstash.new + Lograge::Formatters::Raw.new # Returns a ruby hash object +``` + +In addition to the formatters, you can manipulate the data your self by passing +an object which responds to #call: + +```ruby +# config/environments/production.rb +MyApp::Application.configure do + config.lograge.formatter = ->(data) { "Called #{data[:controller]}" } # data is a ruby hash +end +``` **Internals** Thanks to the notification system that was introduced in Rails 3, replacing the logging is easy. Lograge unhooks all subscriptions from