This project is archived and is in readonly mode.

#1307 ✓stale
Gary Gabriel

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

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>

Attachments

Pages