Humorously informative Rails logging

I’ll just leave this here:

 

01 module ActiveSupport
02   # Format the buffered logger with timestamp/severity info.
03   class BufferedLogger
04     NUMBER_TO_NAME_MAP  = {0=>'meh'1=>'fyi'2=>'hmm'3=>'wtf'4=>'omg'5=>'???'}
05     NUMBER_TO_COLOR_MAP = {0=>'1;30',  1=>'0;36'2=>'0;33'3=>'1;33',  4=>'1;31',  5=>'0;37'}
06  
07     def add(severity, message = nil, progname = nil, &block)
08       return if @level > severity
09       sevstring = NUMBER_TO_NAME_MAP[severity]
10       color     = NUMBER_TO_COLOR_MAP[severity]
11  
12       message = (message || (block && block.call) || progname).to_s
13       message = "\033[0;37m#{Time.now.to_s(:db)}\033[0m [\033[#{color}m" + sprintf("%-3s","#{sevstring}") + "\033[0m] #{message.strip} (pid:#{$$})\n" unless message[-1] == ?\n
14       buffer << message
15       auto_flush
16       message
17     end
18   end
19 end

(To use, put this code in an initializer in config/initializers and restart. Provides highly-readable, timestamped, colorized logging for your rails app.)

Source : http://cbpowell.wordpress.com/2011/12/08/humorously-informative-rails-logging/