Extended maintenance of Ruby 1.9.3 ended on February 23, 2015. Read more

In Files

  • webrick/log.rb

Class/Module Index [+]

Quicksearch

WEBrick::BasicLog

A generic logging class

Constants

DEBUG

Attributes

level[RW]

log-level, messages above this level will be logged

Public Class Methods

new(log_file=nil, level=nil) click to toggle source

Initializes a new logger for log_file that outputs messages at level or higher. log_file can be a filename, an IO-like object that responds to << or nil which outputs to $stderr.

If no level is given INFO is chosen by default

 
               # File webrick/log.rb, line 30
def initialize(log_file=nil, level=nil)
  @level = level || INFO
  case log_file
  when String
    @log = open(log_file, "a+")
    @log.sync = true
    @opened = true
  when NilClass
    @log = $stderr
  else
    @log = log_file  # requires "<<". (see BasicLog#log)
  end
end
            

Public Instance Methods

<<(obj) click to toggle source

Synonym for log(INFO, obj.to_s)

 
               # File webrick/log.rb, line 64
def <<(obj)
  log(INFO, obj.to_s)
end
            
close() click to toggle source

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

 
               # File webrick/log.rb, line 46
def close
  @log.close if @opened
  @log = nil
end
            
debug(msg) click to toggle source

Shortcut for logging a DEBUG message

 
               # File webrick/log.rb, line 77
def debug(msg) log(DEBUG, "DEBUG " << format(msg)); end
            
debug?() click to toggle source

Will the logger output DEBUG messages?

 
               # File webrick/log.rb, line 88
def debug?; @level >= DEBUG; end
            
error(msg) click to toggle source

Shortcut for logging an ERROR message

 
               # File webrick/log.rb, line 71
def error(msg) log(ERROR, "ERROR " << format(msg)); end
            
error?() click to toggle source

Will the logger output ERROR messages?

 
               # File webrick/log.rb, line 82
def error?; @level >= ERROR; end
            
fatal(msg) click to toggle source

Shortcut for logging a FATAL message

 
               # File webrick/log.rb, line 69
def fatal(msg) log(FATAL, "FATAL " << format(msg)); end
            
fatal?() click to toggle source

Will the logger output FATAL messages?

 
               # File webrick/log.rb, line 80
def fatal?; @level >= FATAL; end
            
info(msg) click to toggle source

Shortcut for logging an INFO message

 
               # File webrick/log.rb, line 75
def info(msg)  log(INFO,  "INFO  " << format(msg)); end
            
info?() click to toggle source

Will the logger output INFO messages?

 
               # File webrick/log.rb, line 86
def info?;  @level >= INFO; end
            
log(level, data) click to toggle source

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

 
               # File webrick/log.rb, line 55
def log(level, data)
  if @log && level <= @level
    data += "\n" if /\n\Z/ !~ data
    @log << data
  end
end
            
warn(msg) click to toggle source

Shortcut for logging a WARN message

 
               # File webrick/log.rb, line 73
def warn(msg)  log(WARN,  "WARN  " << format(msg)); end
            
warn?() click to toggle source

Will the logger output WARN messages?

 
               # File webrick/log.rb, line 84
def warn?;  @level >= WARN; end
            

Commenting is here to help enhance the documentation. For example, code samples, or clarification of the documentation.

If you have questions about Ruby or the documentation, please post to one of the Ruby mailing lists. You will get better, faster, help that way.

If you wish to post a correction of the docs, please do so, but also file bug report so that it can be corrected for the next release. Thank you.

If you want to help improve the Ruby documentation, please visit Documenting-ruby.org.