123456789_123456789_123456789_123456789_123456789_

Class: WEBrick::Log

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
self, BasicLog
Instance Chain:
self, BasicLog
Inherits: WEBrick::BasicLog
Defined in: lib/webrick/log.rb

Overview

A logging class that prepends a timestamp to each message.

Constant Summary

BasicLog - Inherited

DEBUG, ERROR, FATAL, INFO, WARN

Class Method Summary

BasicLog - Inherited

.new

Initializes a new logger for log_file that outputs messages at level or higher.

Instance Attribute Summary

  • #time_format rw

    Format of the timestamp which is applied to each logged line.

BasicLog - Inherited

#level

log-level, messages above this level will be logged.

#debug?

Will the logger output DEBUG messages?

#error?

Will the logger output ERROR messages?

#fatal?

Will the logger output FATAL messages?

#info?

Will the logger output INFO messages?

#warn?

Will the logger output WARN messages?

Instance Method Summary

BasicLog - Inherited

#<<

Synonym for log(INFO, obj.to_s).

#close

Closes the logger (also closes the log device associated to the logger).

#debug

Shortcut for logging a DEBUG message.

#error

Shortcut for logging an ERROR message.

#fatal

Shortcut for logging a FATAL message.

#info

Shortcut for logging an INFO message.

#log

Logs data at level if the given level is above the current log level.

#warn

Shortcut for logging a WARN message.

#format

Formats arg for the logger.

Constructor Details

.new(log_file = nil, level = nil) ⇒ Log

Same as BasicLog#initialize

You can set the timestamp format through #time_format

[ GitHub ]

  
# 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 (rw)

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

[ GitHub ]

  
# File 'lib/webrick/log.rb', line 136

attr_accessor :time_format

Instance Method Details

#log(level, data)

Same as BasicLog#log

[ GitHub ]

  
# File 'lib/webrick/log.rb', line 149

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