Created
June 14, 2009 17:19
-
-
Save koseki/129754 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BufferedLogger format patch. | |
# Install into config/initializer/buffered_logger_format.rb | |
# | |
# - https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/1307-bufferedlogger-should-support-message-formatting | |
# - http://saikyoline.jp/weblog/2008/07/01/013418.html | |
# - http://github.com/moro/logger_exception_format/tree/master | |
module ActiveSupport | |
class BufferedLogger | |
def add(severity, message = nil, progname = nil, &block) | |
return if @level > severity | |
# Exception | |
if message.is_a? Exception | |
message = "#{message.message}(#{message.class})\n" + | |
message.backtrace.to_a.map{|t| " #{t}" }.join("\n") | |
end | |
message = (message || (block && block.call) || progname).to_s | |
# If a newline is necessary then create a new message ending with a newline. | |
# Ensures that the original message is not mutated. | |
message = "#{message}\n" unless message[-1] == ?\n | |
# Format. | |
message = "#{Time.now.iso8601(3)} [#{SEV_LABEL[severity]}] #{message}" | |
buffer << message | |
auto_flush | |
message | |
end | |
SEV_LABEL = {} | |
for severity in Severity.constants | |
SEV_LABEL[Severity.const_get(severity)] = severity | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment