Skip to content

Instantly share code, notes, and snippets.

@lguardiola
Created May 27, 2010 18:02
Show Gist options
  • Save lguardiola/416123 to your computer and use it in GitHub Desktop.
Save lguardiola/416123 to your computer and use it in GitHub Desktop.
Formatter for standard lib logger
# 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