Skip to content

Instantly share code, notes, and snippets.

@afair
Created March 30, 2010 20:47
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afair/349579 to your computer and use it in GitHub Desktop.
Save afair/349579 to your computer and use it in GitHub Desktop.
require 'active_support'
class MyLogger < ActiveSupport::BufferedLogger
SEVERITY_NAME = %w( DEBUG INFO WARN ERROR FATAL UNKNOWN )
def custom_line(severity, message)
# Customized Log Format!
message = [Time.now.strftime("%Y-%m-%d %H:%M:%S"), ENV['BL_JOB_ID']||$$, SEVERITY_NAME[severity], message].join("\t")
end
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.
message = "#{message}\n" unless message[-1] == ?\n
message = custom_line(severity, message) # <== CUSTOMIZED
buffer << message
auto_flush
message
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment