Class: WEBrick::Log
Overview
A logging class that prepends a timestamp to each message.
Constant Summary
Constants inherited from BasicLog
BasicLog::DEBUG, BasicLog::ERROR, BasicLog::FATAL, BasicLog::INFO, BasicLog::WARN
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
142 143 144 145 |
# File 'lib/webrick/log.rb', line 142 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]"
136 137 138 |
# File 'lib/webrick/log.rb', line 136 def time_format @time_format end |
Instance Method Details
#log(level, data) ⇒ Object
Same as BasicLog#log
149 150 151 152 153 |
# File 'lib/webrick/log.rb', line 149 def log(level, data) tmp = Time.now.strftime(@time_format) tmp << " " << data super(level, tmp) end |