Class: Loggability::Formatter
- Inherits:
-
Object
- Object
- Loggability::Formatter
- Defined in:
- lib/loggability/formatter.rb
Overview
An abstract base class for Loggability log formatters.
Direct Known Subclasses
Defined Under Namespace
Classes: Color, Default, HTML, Structured
Instance Attribute Summary collapse
-
#derivatives ⇒ Object
readonly
Derivative classes, keyed by name.
Class Method Summary collapse
-
.create(type, *args) ⇒ Object
Create a formatter of the specified
type, loading it if it hasn’t already been loaded. -
.inherited(subclass) ⇒ Object
Inherited hook – add subclasses to the ::derivatives Array.
Instance Method Summary collapse
-
#call(severity, time, progname, message) ⇒ Object
Create a log message from the given
severity,time,progname, andmessageand return it.
Instance Attribute Details
#derivatives ⇒ Object (readonly)
Derivative classes, keyed by name
13 14 15 |
# File 'lib/loggability/formatter.rb', line 13 def derivatives @derivatives end |
Class Method Details
.create(type, *args) ⇒ Object
Create a formatter of the specified type, loading it if it hasn’t already been loaded.
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/loggability/formatter.rb', line 33 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) ⇒ Object
Inherited hook – add subclasses to the ::derivatives Array.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/loggability/formatter.rb', line 18 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 |
Instance Method Details
#call(severity, time, progname, message) ⇒ Object
Create a log message from the given severity, time, progname, and message and return it.
49 50 51 52 |
# File 'lib/loggability/formatter.rb', line 49 def call( severity, time, progname, ) raise NotImplementedError, "%p doesn't implement required method %s" % [ self.class, __method__ ] end |