class DRbService::LogFormatter

A alternate formatter for Logger instances.

Usage

require 'drbservice/utils'
DRbService.logger.formatter = DRbService::LogFormatter.new( DRbService.logger )

Version

$Id: utils.rb,v 87bc5aa9e2be 2011/08/29 21:05:42 ged $

Authors

Copyright © 2010, 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.

Constants

DEFAULT_DEBUG_FORMAT

The format to output if debugging is turned on

DEFAULT_FORMAT

The format to output unless debugging is turned on

Attributes

debug_format[RW]

The logging format string that’s used when outputting in debug mode

format[RW]

The logging format string

logger[RW]

The Logger object associated with the formatter

Public Instance Methods

call( severity, time, progname, msg ) click to toggle source

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/drbservice/utils.rb, line 134
def call( severity, time, progname, msg )
        args = [
                time.strftime( '%Y-%m-%d %H:%M:%S' ),                         # %1$s
                time.usec,                                                    # %2$d
                Process.pid,                                                  # %3$d
                Thread.current == Thread.main ? 'main' : Thread.object_id,    # %4$s
                severity,                                                     # %5$s
                progname,                                                     # %6$s
                msg                                                           # %7$s
        ]

        if @logger.level == Logger::DEBUG
                return self.debug_format % args
        else
                return self.format % args
        end
end

Protected Instance Methods

initialize( logger, format=DEFAULT_FORMAT, debug=DEFAULT_DEBUG_FORMAT ) click to toggle source

Initialize the formatter with a reference to the logger so it can check for log level.

Calls superclass method
# File lib/drbservice/utils.rb, line 110
def initialize( logger, format=DEFAULT_FORMAT, debug=DEFAULT_DEBUG_FORMAT ) # :notnew:
        @logger       = logger
        @format       = format
        @debug_format = debug

        super()
end