Loggability::
Formatter
class
An abstract base class for Loggability
log formatters.
Create a formatter of the specified type
, loading it if it hasn’t already been loaded.
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 hook – add subclasses to the ::derivatives Array.
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
call( severity, time, progname, message )
Create a log message from the given severity
, time
, progname
, and message
and return it.
def call( severity, time, progname, message )
raise NotImplementedError, "%p doesn't implement required method %s" %
[ self.class, __method__ ]
end
Derivative classes, keyed by name
singleton_class.attr_reader( :derivatives )