Logger::Formatter
A alternate formatter for Logger instances.
require 'redleaf/utils' Redleaf.logger.formatter = Redleaf::LogFormatter.new( Redleaf.logger )
$Id$
Copyright © 2008-2009, Michael Granger All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The format to output unless debugging is turned on
The format to output if debugging is turned on
Log using either the DEBUG_FORMAT if the associated logger is at ::DEBUG level or using FORMAT if it’s anything less verbose.
# File lib/redleaf/utils.rb, line 229 229: def call( severity, time, progname, msg ) 230: args = [ 231: time.strftime( '%Y-%m-%d %H:%M:%S' ), # %1$s 232: time.usec, # %2$d 233: Process.pid, # %3$d 234: Thread.current == Thread.main ? 'main' : Thread.object_id, # %4$s 235: severity, # %5$s 236: progname, # %6$s 237: msg # %7$s 238: ] 239: 240: if @logger.level == Logger::DEBUG 241: return self.debug_format % args 242: else 243: return self.format % args 244: end 245: end
Initialize the formatter with a reference to the logger so it can check for log level.
# File lib/redleaf/utils.rb, line 205 205: def initialize( logger, format=DEFAULT_FORMAT, debug=DEFAULT_DEBUG_FORMAT ) # :notnew: 206: @logger = logger 207: @format = format 208: @debug_format = debug 209: 210: super() 211: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.