Hodel 3000 Compliant Logger
TopFunky introduced us all to the concept of a Hodel 3000 Compliant Logger. In the real world this logger let's you take advantage of the pl_analyze tools for log analysis by reformatting the log to a format it can parse.
The logger:
require 'logger'
require 'English'
# Jan 2 03:38:05 topfunky postfix/postqueue[2947]: warning blah blah blah
# A logger for use with pl_analyze and other tools that expect syslog-style log output.
class Hodel3000CompliantLogger < Logger
# Note: If you are using FastCGI you may need to hard-code the hostname here instead of using Socket.gethostname
def format_message(severity, timestamp, msg, progname)
"#{timestamp.strftime("%b %d %H:%M:%S")} #{Socket.gethostname.split('.').first} rails[#{$PID}]: #{progname.gsub(/\n/, '').lstrip}\n"
end
end
And to use it in your app just reset your logger (in your production.rb for example)
# The new automagically, log-a-fantastic hodel 3000 compliant logger (now in technicolor)
config.logger = Hodel3000CompliantLogger.new(config.log_path)