Class: WEBrick::Log
Overview
A logging class that prepends a timestamp to each message.
Instance Attribute Summary collapse
-
#time_format ⇒ Object
Format of the timestamp which is applied to each logged line.
Attributes inherited from BasicLog
Instance Method Summary collapse
-
#initialize(log_file = nil, level = nil) ⇒ Log
constructor
Same as BasicLog#initialize.
-
#log(level, data) ⇒ Object
Same as BasicLog#log.
Methods inherited from BasicLog
#<<, #close, #debug, #debug?, #error, #error?, #fatal, #fatal?, #info, #info?, #warn, #warn?
Constructor Details
#initialize(log_file = nil, level = nil) ⇒ Log
Same as BasicLog#initialize
You can set the timestamp format through #time_format
123 124 125 126 |
# File 'lib/webrick/log.rb', line 123 def initialize(log_file=nil, level=nil) super(log_file, level) @time_format = "[%Y-%m-%d %H:%M:%S]" end |
Instance Attribute Details
#time_format ⇒ Object
Format of the timestamp which is applied to each logged line. The default is "[%Y-%m-%d %H:%M:%S]"
117 118 119 |
# File 'lib/webrick/log.rb', line 117 def time_format @time_format end |
Instance Method Details
#log(level, data) ⇒ Object
Same as BasicLog#log
130 131 132 133 134 |
# File 'lib/webrick/log.rb', line 130 def log(level, data) tmp = Time.now.strftime(@time_format) tmp << " " << data super(level, tmp) end |