Treequel::

LogFormatter

class
Superclass
Logger::Formatter

A alternate formatter for Logger instances. @private

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

anchor
call( severity, time, progname, msg )

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/treequel/utils.rb, line 50
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

anchor
initialize( logger, format=DEFAULT_FORMAT, debug=DEFAULT_DEBUG_FORMAT )

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

# File lib/treequel/utils.rb, line 26
def initialize( logger, format=DEFAULT_FORMAT, debug=DEFAULT_DEBUG_FORMAT ) # :notnew:
        @logger       = logger
        @format       = format
        @debug_format = debug

        super()
end