Rails Integration
-
Gemfile: Add
gem 'enhanced-logger'Removegem 'rails_12factor' -
In Application Controller, add
before_action { logger.set_env( env )}after_action { logger.clear_env } -
In
config/application.rb, addconfig.logger = EnhancedLogger::Logger.new(EnhancedLogger::Logger::LEVELS[:info]) -
Set log level in environment/production.rb, test.rb and/or development.rb. Log levels are :debug, :info, :warn, :error, and :fatal.
config.log_level = :debug -
Use logger the same way as Rails logger.
Rails.logger.info 'log message' -
All HTTP requests to services running Enhanced Logger should set the X-Remote-Request-Id header.
Rack Integration
-
Gemfile: Add
gem 'enhanced-logger' -
App:
require 'enhanced-logger' -
Instantiate the logger. For example:
class App @logger = EnhancedLogger::Logger.new( EnhancedLogger::Logger::LEVELS[ :error ])
-
Before each request is processed:
@logger.set_env( env ) -
After each request is processed:
@logger.clear_env -
To use logger:
@logger.info 'log message' -
All HTTP requests to services running Enhanced Logger should set the X-Remote-Request-Id header.
Initializer Options
The initializer takes an options hash. To you exclude files from appearing as the caller,
exclude_files = {exclude_files:['log', 'log_helper']}
EnhancedLogger::Logger.new( EnhancedLogger::Logger::LEVELS[ :error ], exclude_files)
rails_12factor gem
This gem does not work with the rails_12factor gem.