Fluent logger.
- Rails 4, 5, 6
Add this line to your application's Gemfile:
gem 'act-fluent-logger-rails'
And then execute:
$ bundle
Or install it yourself as:
$ gem install act-fluent-logger-rails
in config/environments/production.rb
config.log_level = :info
config.logger = ActFluentLoggerRails::Logger.
new(log_tags: {
ip: :ip,
ua: :user_agent,
uid: ->(request) { request.session[:uid] }
})
Don't use config.log_tags.
development:
fluent_host: '127.0.0.1'
fluent_port: 24224
tag: 'foo'
messages_type: 'string'
severity_key: 'level' # default severity
test:
fluent_host: '127.0.0.1'
fluent_port: 24224
tag: 'foo'
messages_type: 'string'
severity_key: 'level' # default severity
production:
fluent_host: '127.0.0.1'
fluent_port: 24224
tag: 'foo'
messages_type: 'string'
severity_key: 'level' # default severity
http://fluentd.example.com:42442/foo?messages_type=string&severity_key=level
config.logger = ActFluentLoggerRails::Logger.
new(settings: {
host: '127.0.0.1',
port: 24224,
tag: 'foo',
messages_type: 'string',
severity_key: 'level'
})
- fluent_host: The host name of Fluentd.
- fluent_port: The port number of Fluentd.
- tag: The tag of the Fluentd event.
- messages_type: The type of log messages. 'string' or 'array'. If it is 'string', the log messages is a String.
2013-01-18T15:04:50+09:00 foo {"messages":"Started GET \"/\" for 127.0.0.1 at 2013-01-18 15:04:49 +0900\nProcessing by TopController#index as HTML\nCompleted 200 OK in 635ms (Views: 479.3ms | ActiveRecord: 39.6ms)"],"severity":"INFO"}
If it is 'array', the log messages is an Array.
2013-01-18T15:04:50+09:00 foo {"messages":["Started GET \"/\" for 127.0.0.1 at 2013-01-18 15:04:49 +0900","Processing by TopController#index as HTML","Completed 200 OK in 635ms (Views: 479.3ms | ActiveRecord: 39.6ms)"],"severity":"INFO"}
- severity_key: The key of severity(DEBUG, INFO, WARN, ERROR).
You can add any tags at run time.
logger[:foo] = "foo value"
Typical usage is as a replacement for the default Rails logger, in which case
messages are collected and flushed automatically as part of the request
lifecycle. If you wish to use it instead as a separate logger and log to it
manually then it is necessary to initialize with the flush_immediately
flag.
ActFluentLoggerRails::Logger.new(flush_immediately: true)
- Fork it
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create new Pull Request
gem install appraisal
bundle exec appraisal bundle
bundle exec appraisal rake