In Files

  • webrick/log.rb

Class/Module Index [+]

Quicksearch

WEBrick::BasicLog

Constants

DEBUG

Attributes

level[RW]

Public Class Methods

new(log_file=nil, level=nil) click to toggle source
 
               # File webrick/log.rb, line 18
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
 
               # File webrick/log.rb, line 44
def <<(obj)
  log(INFO, obj.to_s)
end
            
close() click to toggle source
 
               # File webrick/log.rb, line 32
def close
  @log.close if @opened
  @log = nil
end
            
debug(msg) click to toggle source
 
               # File webrick/log.rb, line 52
def debug(msg) log(DEBUG, "DEBUG " << format(msg)); end
            
debug?() click to toggle source
 
               # File webrick/log.rb, line 58
def debug?; @level >= DEBUG; end
            
error(msg) click to toggle source
 
               # File webrick/log.rb, line 49
def error(msg) log(ERROR, "ERROR " << format(msg)); end
            
error?() click to toggle source
 
               # File webrick/log.rb, line 55
def error?; @level >= ERROR; end
            
fatal(msg) click to toggle source
 
               # File webrick/log.rb, line 48
def fatal(msg) log(FATAL, "FATAL " << format(msg)); end
            
fatal?() click to toggle source
 
               # File webrick/log.rb, line 54
def fatal?; @level >= FATAL; end
            
info(msg) click to toggle source
 
               # File webrick/log.rb, line 51
def info(msg)  log(INFO,  "INFO  " << format(msg)); end
            
info?() click to toggle source
 
               # File webrick/log.rb, line 57
def info?;  @level >= INFO; end
            
log(level, data) click to toggle source
 
               # File webrick/log.rb, line 37
def log(level, data)
  if @log && level <= @level
    data += "\n" if /\n\Z/ !~ data
    @log << data
  end
end
            
warn(msg) click to toggle source
 
               # File webrick/log.rb, line 50
def warn(msg)  log(WARN,  "WARN  " << format(msg)); end
            
warn?() click to toggle source
 
               # File webrick/log.rb, line 56
def warn?;  @level >= WARN; end