Class: WEBrick::Log

Inherits:
BasicLog show all
Defined in:
lib/webrick/log.rb

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

Attributes inherited from BasicLog

#level

Instance Method Summary collapse

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



143
144
145
146
# File 'lib/webrick/log.rb', line 143

def initialize(log_file=nil, level=nil)
  super(log_file, level)
  @time_format = "[%Y-%m-%d %H:%M:%S]"
end

Instance Attribute Details

#time_formatObject

Format of the timestamp which is applied to each logged line. The default is "[%Y-%m-%d %H:%M:%S]"



137
138
139
# File 'lib/webrick/log.rb', line 137

def time_format
  @time_format
end

Instance Method Details

#log(level, data) ⇒ Object

Same as BasicLog#log



150
151
152
153
154
# File 'lib/webrick/log.rb', line 150

def log(level, data)
  tmp = Time.now.strftime(@time_format)
  tmp << " " << data
  super(level, tmp)
end