This project is archived and is in readonly mode.
BufferedLogger should support message formatting.
Reported by Gary Gabriel | October 31st, 2008 @ 03:27 AM | in 2.x
Currently, ActiveSupport::BufferedLogger cannot do any message formatting. It would be very useful to see the severity of the message along with a timestamp for anything that is logged. This functionality is supported by the built-in Ruby Logger class, though only the time format is customizable.
I have created a patch allows you to specify your own formatting function to format the message in any way you wish. The default format remains the same - just the message itself. But you can do something like:
logger = ActiveSupport::BufferedLogger.new(STDOUT) logger.formatter = lambda { |severity_label, message| "[#{severity_label}] #{message}" } logger.info "test"
and get this in the log:
[INFO] test
You could add other things to the format, like a timestamp. The function is always called with 2 arguments, the first one being a string equal to the severity level, and the second one being the message itself. The severity levels are from the Severity module inside the BufferedLogger class - "DEBUG", "INFO", "WARN", etc.
I have also added 2 tests for this code.
Comments and changes to this ticket
-
jrochkind November 17th, 2008 @ 11:39 PM
This functionality would be much welcome, it seems odd that it was left out.
I'm really not sure why BufferedLogger doesn't sub-class the standard Ruby Logger in the first place though, and allow formatting through the same way the standard Ruby Logger does, with a Logger::Formatter object?
I guess this patch does use a Logger::Formatter type object, but I wonder why we're re-inventing the wheel instead of basing it on ruby Logger?
-
Pratik January 19th, 2009 @ 08:09 PM
- Milestone cleared.
- Assigned user set to Pratik
- Title changed from [PATCH] BufferedLogger should support message formatting. to BufferedLogger should support message formatting.
-
Pratik January 30th, 2009 @ 06:05 PM
- Milestone set to 2.x
-
Pratik January 30th, 2009 @ 06:26 PM
- Assigned user changed from Pratik to Yehuda Katz (wycats)
-
Pratik April 21st, 2009 @ 03:29 PM
- State changed from new to stale
-
Tony Collen August 21st, 2009 @ 05:42 PM
No love for this ticket? This would be incredibly useful right now.
-
Deleted User September 23rd, 2009 @ 07:41 PM
Could we change this from 'stale' to 'about time'? Why would any system include a logger with no formatting option?
-
Jeff Kreeftmeijer November 8th, 2010 @ 08:27 AM
- Tag cleared.
- Importance changed from to Low
Automatic cleanup of spam.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>