1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[ruby/logger] split logger classes/modules into separate files

f10ce9fff2
This commit is contained in:
Colby Swandale 2018-12-12 14:08:35 +11:00 committed by Hiroshi SHIBATA
parent 136196785b
commit bbe157f340
No known key found for this signature in database
GPG key ID: F9CF13417264FAC2
8 changed files with 308 additions and 294 deletions

35
lib/logger/formatter.rb Normal file
View file

@ -0,0 +1,35 @@
class Logger
# Default formatter for log messages.
class Formatter
Format = "%s, [%s#%d] %5s -- %s: %s\n".freeze
attr_accessor :datetime_format
def initialize
@datetime_format = nil
end
def call(severity, time, progname, msg)
Format % [severity[0..0], format_datetime(time), $$, severity, progname,
msg2str(msg)]
end
private
def format_datetime(time)
time.strftime(@datetime_format || "%Y-%m-%dT%H:%M:%S.%6N ".freeze)
end
def msg2str(msg)
case msg
when ::String
msg
when ::Exception
"#{ msg.message } (#{ msg.class })\n" <<
(msg.backtrace || []).join("\n")
else
msg.inspect
end
end
end
end