Skip to content

Instantly share code, notes, and snippets.

@theirishpenguin
Created January 1, 2012 20:44
Show Gist options
  • Save theirishpenguin/1548299 to your computer and use it in GitHub Desktop.
Save theirishpenguin/1548299 to your computer and use it in GitHub Desktop.
Override Logging messages in Rails
# drop this into config/initializers/enhanced_logger.rb
raise 'Check logger workaround if Rails version has changed' unless
Rails::version == "3.0.7"
# Overrides /path/to/gems/activesupport-3.0.7/lib/active_support/buffered_logger.rb
module ActiveSupport
class BufferedLogger
def add(severity, message = nil, progname = nil, &block)
return if @level > severity
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.
# eg. Here we print out the log level at the start of the message
# => Severity.constants[severity]}_LEVEL
message = "#{Severity.constants[severity]}_LEVEL #{message}\n" unless message[-1] == ?\n
buffer << message
auto_flush
message
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment