[Mongrel] Timestamping in log file?

Paolo Montrasio
Tue, 12 Feb 2008 22:19:03 -0000

I added timestamps to my mongrel logs by adding these lines to
config/environment.rb:

class Logger
  def format_message(severity, timestamp, progname, msg)
    time = timestamp.getutc.strftime("%Y%m%d%H%M%S")
    "\n#{time}:#{severity.to_s.upcase}:#{$$}:#{msg}"
  end
end

It logs messages like this:

Processing MyController#my_method (for 127.0.0.1 at 2007-12-29 14:37:54)
 [POST]
20071229133754:INFO:23386:  Session ID: d7022e387306cc4e5fea107080014bf1
20071229133754:INFO:23386:  Parameters:
{"action"=>"my_method",
"controller"=>"my", "id"=>"1"}
20071229133754:DEBUG:23386:ID = 1

The process id turned out to be extremely useful to debug some weird
things my application started doing when moved from the single mongrel
development environment to a multi mongrel one in production.

Furthermore, sometimes the logs from two or more requests get mixed
together (I guess that it can''t be helped) and the process id helps to
connect a log line to its request.


Paolo
--
Posted via http://www.ruby-forum.com/.