Title: #{version} Log4r Manual Template: main.html Id: $Id$
require 'log4r' include Log4r # create a logger named 'mylog' that logs to stdout mylog = Logger.new 'mylog' mylog.outputters = Outputter.stdout # Now we can log. def do_log(log) log.debug "This is a message with level DEBUG" log.info "This is a message with level INFO" log.warn "This is a message with level WARN" log.error "This is a message with level ERROR" log.fatal "This is a message with level FATAL" end do_log(mylog)
DEBUG mylog: This is a message with level DEBUG INFO mylog: This is a message with level INFO WARN mylog: This is a message with level WARN ERROR mylog: This is a message with level ERROR FATAL mylog: This is a message with level FATAL
mylog = Logger['mylog'] # Get our logger back
mylog.level = ERROR
ERROR mylog: This is a message with level ERROR FATAL mylog: This is a message with level FATAL
DEBUG < INFO < WARN < ERROR < FATAL
log.debug( myobj.collect{|e| e.collect{|p| p.to_s}} )
if log.debug? log.debug( myobj.collect{|e| e.collect{|p| p.to_s}} ) end
log.debug { myobj.collect{|e| e.collect{|p| p.to_s} }
Logger['mylog'].trace = true
<formatter type="PatternFormatter"> <!-- %C shows full ancestry --> <pattern>[%l %C] %m</pattern> </formatter>
[DEBUG cain::grandpa::pa::me] Log message
noisylog = Logger.root noisy.debug "This won't do anything"
root.level=OFF
after defining some loggers, none of the loggers will change their level
to OFF
. There is a good reason for this behavior.
IOOutputter
's IO
is closed,
the IOOutputter
changes its level to OFF
OFF
, the overhead of checking to
see if a log event should be logged nearly vanishes. This was accomplished by
dynamically redefining the unloggable logging methods to do nothing.
In the future, Log4r's performance critical features will be written as a C
extension to Ruby. It will still be optional, but it will be available for
those who absolutely need to squeeze every last ounce of performance out of
Log4r. (No longer in the works, unfortunately.)