Skip to content

Instantly share code, notes, and snippets.

@goromlagche
Last active August 24, 2018 11:39
Show Gist options
  • Select an option

  • Save goromlagche/35070f98073102d2429e588197257a93 to your computer and use it in GitHub Desktop.

Select an option

Save goromlagche/35070f98073102d2429e588197257a93 to your computer and use it in GitHub Desktop.
writing a generic log formatter for rails and sneakers
module App
class Application < Rails::Application
...
config.log_tags = [:request_id]
...
end
end
class CustomFormatter < ActiveSupport::Logger::SimpleFormatter
include ActiveSupport::TaggedLogging::Formatter
def call(severity, timestamp, _progname, msg)
{
timestamp: timestamp,
level: severity,
guid: current_tags.first || SecureRandom.uuid, # use request_id for rails and generate a uuid for sneakers
pid: $PID,
message: msg
}.to_json.to_s + " \n"
end
end
Rails.logger.formatter = CustomFormatter.new
Sneakers.logger.formatter = CustomFormatter.new
A very simple generic log formatter for sneakers and rails.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment