class WEBrick::BasicLog
def <<(obj)
#
def <<(obj) log(INFO, obj.to_s) end
def close
#
def close @log.close if @opened @log = nil end
def debug(msg) log(DEBUG, "DEBUG " + format(msg)); end
def debug(msg) log(DEBUG, "DEBUG " + format(msg)); end
def debug?; @level >= DEBUG; end
def debug?; @level >= DEBUG; end
def error(msg) log(ERROR, "ERROR " + format(msg)); end
def error(msg) log(ERROR, "ERROR " + format(msg)); end
def error?; @level >= ERROR; end
def error?; @level >= ERROR; end
def fatal(msg) log(FATAL, "FATAL " + format(msg)); end
def fatal(msg) log(FATAL, "FATAL " + format(msg)); end
def fatal?; @level >= FATAL; end
def fatal?; @level >= FATAL; end
def format(arg)
* If +arg+ responds to #to_str, it will return it.
the back trace.
* If +arg+ is an Exception, it will format the error message and
Formats +arg+ for the logger
#
def format(arg) if arg.is_a?(Exception) +"#{arg.class}: #{AccessLog.escape(arg.message)}\n\t" << arg.backtrace.join("\n\t") << "\n" elsif arg.respond_to?(:to_str) AccessLog.escape(arg.to_str) else arg.inspect end end
def info(msg) log(INFO, "INFO " + format(msg)); end
def info(msg) log(INFO, "INFO " + format(msg)); end
def info?; @level >= INFO; end
def info?; @level >= INFO; end
def initialize(log_file=nil, level=nil)
def initialize(log_file=nil, level=nil) @level = level || INFO case log_file when String @log = File.open(log_file, "a+") @log.sync = true @opened = true when NilClass @log = $stderr else @log = log_file # requires "<<". (see BasicLog#log) end end
def log(level, data)
def log(level, data) if @log && level <= @level data += "\n" if /\n\Z/ !~ data @log << data end end
def warn(msg) log(WARN, "WARN " + format(msg)); end
def warn(msg) log(WARN, "WARN " + format(msg)); end
def warn?; @level >= WARN; end
def warn?; @level >= WARN; end