Skip to content

Instantly share code, notes, and snippets.

@selvan
Created June 15, 2012 10:18
Show Gist options
  • Save selvan/2935745 to your computer and use it in GitHub Desktop.
Save selvan/2935745 to your computer and use it in GitHub Desktop.
Custom Log Formatting - Rails 3
logger = Logger.new(File.join( Rails.root, "log", "my_#{ Rails.env}.log"), 'daily')
logger.level = Logger::INFO
logger.formatter = proc do |severity, datetime, progname, msg|
"#{datetime.strftime("%B %d %H:%M:%S")} #{Socket.gethostname}, [#{$$}]:, #{severity} MY_WEBAPP, #{msg}\n"
end
tag_log = ActiveSupport::TaggedLogging.new(logger)
config.logger = tag_log
# above code will produce log in format as shown below,
<Month> <Day> <HH:MM:SS> <HostName>, [pid]:, <Level>, <Category>, <Msg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment