Tag rails logs with useful information

Just learned about tagged logging in rails. Did you know you can tag a log by using

logger.tagged('Your Tag') { logger.info('Message') }


You can also do it globally with

# config/application.rb
config.log_tags = [:method_on_request_object, lambda { |request| request.method.modifier_method }]


Add client Device OS and OS Version information to logs (requires clients to send X-OS and X-OS-Version headers)

# config/application.rb
config.log_tags = [ :request_id, lambda { |request| "#{request.headers['HTTP_X_OS']} #{request.headers['HTTP_X_OS_VERSION']}" } ]


828
Joe

Get our stories delivered

From us to your inbox weekly.