Class: Logger::Formatter
Relationships & Source Files | |
Inherits: | Object |
Defined in: | lib/logger/formatter.rb |
Overview
Default formatter for log messages.
Constant Summary
-
DatetimeFormat =
# File 'lib/logger/formatter.rb', line 7"%Y-%m-%dT%H:%M:%S.%6N"
-
Format =
# File 'lib/logger/formatter.rb', line 6"%s, [%s #%d] %5s -- %s: %s\n"
Class Method Summary
- .new ⇒ Formatter constructor
Instance Attribute Summary
Instance Method Summary
- #call(severity, time, progname, msg)
- #format_datetime(time) private
- #msg2str(msg) private
Constructor Details
.new ⇒ Formatter
# File 'lib/logger/formatter.rb', line 11
def initialize @datetime_format = nil end
Instance Attribute Details
#datetime_format (rw)
[ GitHub ]# File 'lib/logger/formatter.rb', line 9
attr_accessor :datetime_format
Instance Method Details
#call(severity, time, progname, msg)
[ GitHub ]# File 'lib/logger/formatter.rb', line 15
def call(severity, time, progname, msg) Format % [severity[0..0], format_datetime(time), Process.pid, severity, progname, msg2str(msg)] end
#format_datetime(time) (private)
[ GitHub ]# File 'lib/logger/formatter.rb', line 22
def format_datetime(time) time.strftime(@datetime_format || DatetimeFormat) end
#msg2str(msg) (private)
[ GitHub ]# File 'lib/logger/formatter.rb', line 26
def msg2str(msg) case msg when ::String msg when ::Exception "#{ msg. } (#{ msg.class })\n#{ msg.backtrace.join("\n") if msg.backtrace }" else msg.inspect end end