Skip to content

Instantly share code, notes, and snippets.

@rickyah
Last active October 1, 2015 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rickyah/1999991 to your computer and use it in GitHub Desktop.
Save rickyah/1999991 to your computer and use it in GitHub Desktop.
Add timestamps and more info to default Rails logger
# Adds timestamps to logs
# put it at the end of environment.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
level = {
0 => "DEBUG",
1 => "INFO",
2 => "WARN",
3 => "ERROR",
4 => "FATAL"
}[severity] || "U"
message = "[%s: %s] %s" % [level, Time.now.strftime("%m%d %H:%M:%S"), message]
message = "#{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