How to format ruby logger to this?
logging, ruby
Solution
try this:
"#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%L')}]: #{msg}\n"
Problem
The default style in ruby logger is: ``` SeverityID, [Date Time mSec #pid] SeverityLabel -- ProgName: message # => D, [2013-11-25T13:31:03.451024 #38180] DEBUG -- : <message...> ``` and I want to make it looks like: ``` SeverityLabel [Date Time mSec #pid]: message # => DEBUG [2013-11-25T13:31:03.451024 #38180]: <message...> ``` I know I can format it like this: ``` logger.formatter = proc do |severity, datetime, progname, msg| "severity [#{datetime}]: #{msg}\n" end # => DEBUG [2013-11-25 13:37:45 -0800]: <message...> ``` but the datetime in proc does NOT look like what it showed in default. I've tried using datetime_format ``` logger.datetime_format = "%Y-%m-%d %H:%M:%S.%L" ``` but it has NO effect on my logger... Also, I cannot find #pid either any thoughts? I've seen the following post: How to format ruby logger? and the doc: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/logger/rdoc/Logger.html Thanks to Some Guy's reply, This is what I ended up doing: ``` logger.formatter = proc do |severity, datetime, progname, msg| "#{severity} [#{datetime.strftime('%Y-%m-%d %H:%M:%S.%6N')} ##{Process.pid}]: #{msg}\n" end ```