Class: Log4Ruby::Appender
- Inherits:
-
Object
- Object
- Log4Ruby::Appender
- Defined in:
- lib/log4ruby/appender.rb
Overview
Base class for appenders.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#formatter ⇒ Object
writeonly
Set the formatter this appender uses.
Instance Method Summary collapse
-
#close ⇒ TrueClass
Closes this appender.
-
#closed? ⇒ TrueClass, FalseClass
Check if this appender is closed.
-
#initialize(level, options = {}) ⇒ Appender
constructor
New appender.
-
#process_log(log) ⇒ Object
Process the log item.
Constructor Details
#initialize(level, options = {}) ⇒ Appender
New appender. This class should be treated as an abstract base class and should not be initialised directly.
20 21 22 23 24 25 26 |
# File 'lib/log4ruby/appender.rb', line 20 def initialize(level, = {}) @level = level @formatter = get_option(, :formatter, false, DefaultFormatter.new) @closed = false at_exit { close } end |
Instance Attribute Details
#formatter=(value) ⇒ Object (writeonly)
Set the formatter this appender uses.
13 14 15 |
# File 'lib/log4ruby/appender.rb', line 13 def formatter=(value) @formatter = value end |
Instance Method Details
#close ⇒ TrueClass
Closes this appender. Logs will not be emitted by this appender any longer. If the appender is already closed, this method should not do anything.
32 33 34 |
# File 'lib/log4ruby/appender.rb', line 32 def close @closed = true end |
#closed? ⇒ TrueClass, FalseClass
Check if this appender is closed.
39 40 41 |
# File 'lib/log4ruby/appender.rb', line 39 def closed? @closed end |
#process_log(log) ⇒ Object
Process the log item.
46 47 48 49 50 51 52 53 |
# File 'lib/log4ruby/appender.rb', line 46 def process_log(log) return if self.closed? return if log[:level] < @level # Format the log item and emit it. string = @formatter.format(log) emit(string, log) end |