Loggability::

Formatter class

An abstract base class for Loggability log formatters.

Public Class Methods

create( type, *args )

Create a formatter of the specified type, loading it if it hasn’t already been loaded.

# File lib/loggability/formatter.rb, line 32
def self::create( type, *args )
        require "loggability/formatter/#{type}"
        type = type.to_sym

        if self.derivatives.key?( type )
                return self.derivatives[ type ].new( *args )
        else
                raise LoadError,
                        "require of %s formatter succeeded (%p), but it didn't load a class named %p::%s" %
                        [ type, self.derivatives, self, type.to_s.capitalize ]
        end
end
inherited( subclass )

Inherited hook – add subclasses to the ::derivatives Array.

# File lib/loggability/formatter.rb, line 17
def self::inherited( subclass )
        super

        if ( name = subclass.name )
                classname = name.sub( /.*::/, '' ).downcase
        else
                classname = "anonymous_%d" % [ subclass.object_id ]
        end

        Loggability::Formatter.derivatives[ classname.to_sym ] = subclass
end

Public Instance Methods

call( severity, time, progname, message )

Create a log message from the given severity, time, progname, and message and return it.

# File lib/loggability/formatter.rb, line 48
def call( severity, time, progname, message )
        raise NotImplementedError, "%p doesn't implement required method %s" %
                [ self.class, __method__ ]
end
unknown()

Derivative classes, keyed by name

# File lib/loggability/formatter.rb, line 12
singleton_class.attr_reader( :derivatives )