Skip to content

Instantly share code, notes, and snippets.

@gkojax
Created February 25, 2013 23:54
Show Gist options
  • Save gkojax/5034489 to your computer and use it in GitHub Desktop.
Save gkojax/5034489 to your computer and use it in GitHub Desktop.
require 'logger'
class MyFormatter < Logger::Formatter
def call(severity, timestamp, progname, msg)
if String === msg then
if msg.nil? or msg.empty? then
return "\n"
else
return "%s %s\n" % [timestamp.strftime("%H:%M:%S"), msg]
end
else
return msg.inspect + "\n"
end
end
end
class MyLogger < Logger
def initialize(file, level = Logger::DEBUG, log_dir = $log_dir)
if file.class.to_s == 'IO' then
super(file, 2)
else
super(log_dir + file, 5, 10*1024*1024)
end
self.formatter = MyFormatter.new
self.level = level
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment