Created
May 27, 2010 18:02
-
-
Save lguardiola/416123 to your computer and use it in GitHub Desktop.
Formatter for standard lib logger
This file contains 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
# storage on lib/gasper/logger/formatter.rb | |
# Usage | |
# LOGGER = Logger.new('log/development.log', 'daily') | |
# LOGGER.formatter = Gasper::Logger::Formatter.new | |
# LOGGER.progname = 'mongodb-json-proxy' | |
# | |
module Gasper | |
module Logger | |
class Formatter | |
# YYYY:MM:DD HH:MM:SS.MS progname(pid) level: message | |
@format = "%s %s(%d) [%s] %s\n" | |
class << self | |
attr_accessor :format | |
end | |
def call(severity, time, progname, msg) | |
self.class.format % [ format_time( time ), progname, $$, severity, msg.to_s ] | |
end | |
private | |
def format_time( time ) | |
time.strftime( "%Y-%m-%d %H:%M:%S." ) + time.usec.to_s | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment