Class: Logging::Layout
- Inherits:
-
Object
- Object
- Logging::Layout
- Defined in:
- lib/logging/layout.rb
Overview
The Layout class provides methods for formatting log events into a string representation. Layouts are used by Appenders to format log events before writing them to the logging destination.
All other Layouts inherit from this class which provides stub methods. Each subclass should provide a format method. A layout can be used by more than one Appender so all the methods need to be thread safe.
Direct Known Subclasses
Instance Method Summary collapse
-
#footer ⇒ Object
call-seq: footer.
-
#format(event) ⇒ Object
call-seq: format( event ).
-
#header ⇒ Object
call-seq: header.
-
#initialize(opts = {}) ⇒ Layout
constructor
call-seq: Layout.new( :format_as => :string ).
Constructor Details
#initialize(opts = {}) ⇒ Layout
call-seq:
Layout.new( :format_as => :string )
Creates a new layout that will format objecs as strings using the given :format_as style. This can be one of :string, :inspect, or :yaml. These formatting commands map to the following object methods:
-
:string => to_s
-
:inspect => inspect
-
:yaml => to_yaml
If the format is not specified then the global object format is used (see Logging#format_as). If the global object format is not specified then :string is used.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/logging/layout.rb', line 33 def initialize( opts = {} ) default = ::Logging.const_defined?('OBJ_FORMAT') ? ::Logging::OBJ_FORMAT : nil f = opts.getopt(:format_as, default) f = f.intern if f.instance_of? String @obj_format = case f when :inspect, :yaml; f else :string end end |
Instance Method Details
#footer ⇒ Object
call-seq:
Returns a footer string to be used at the end of a logging appender.
66 |
# File 'lib/logging/layout.rb', line 66 def ( ) '' end |
#format(event) ⇒ Object
call-seq:
format( event )
Returns a string representation of the given loggging event. It is up to subclasses to implement this method.
51 |
# File 'lib/logging/layout.rb', line 51 def format( event ) nil end |
#header ⇒ Object
call-seq:
header
Returns a header string to be used at the beginning of a logging appender.
59 |
# File 'lib/logging/layout.rb', line 59 def header( ) '' end |