Created
June 15, 2012 10:18
-
-
Save selvan/2935745 to your computer and use it in GitHub Desktop.
Custom Log Formatting - Rails 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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