Class: VCAP::Logging::Sink::BaseSink
- Inherits:
-
Object
- Object
- VCAP::Logging::Sink::BaseSink
- Defined in:
- lib/vcap/logging/sink/base_sink.rb
Overview
Sinks serve as the final destination for log records. Usually they are lightweight wrappers around other objects that perform IO (files and sockets come to mind).
Direct Known Subclasses
Instance Attribute Summary collapse
-
#autoflush ⇒ Object
Returns the value of attribute autoflush.
-
#formatter ⇒ Object
Returns the value of attribute formatter.
-
#opened ⇒ Object
readonly
Returns the value of attribute opened.
Instance Method Summary collapse
-
#add_record(log_record) ⇒ Object
Formats the log record using the configured formatter and NB: Depending on the implementation of write(), this may buffer the record in memory.
-
#close ⇒ Object
Closes any underlying file descriptors and ensures that any log records buffered in memory are flushed.
-
#flush ⇒ Object
Flushes any log records that may have been buffered in memory.
-
#initialize(formatter = nil) ⇒ BaseSink
constructor
A new instance of BaseSink.
-
#open ⇒ Object
Opens any underlying file descriptors, etc.
Constructor Details
#initialize(formatter = nil) ⇒ BaseSink
Returns a new instance of BaseSink.
21 22 23 24 25 26 |
# File 'lib/vcap/logging/sink/base_sink.rb', line 21 def initialize(formatter=nil) @formatter = formatter @opened = false @mutex = Mutex.new @autoflush = false end |
Instance Attribute Details
#autoflush ⇒ Object
Returns the value of attribute autoflush.
19 20 21 |
# File 'lib/vcap/logging/sink/base_sink.rb', line 19 def autoflush @autoflush end |
#formatter ⇒ Object
Returns the value of attribute formatter.
18 19 20 |
# File 'lib/vcap/logging/sink/base_sink.rb', line 18 def formatter @formatter end |
#opened ⇒ Object (readonly)
Returns the value of attribute opened.
17 18 19 |
# File 'lib/vcap/logging/sink/base_sink.rb', line 17 def opened @opened end |
Instance Method Details
#add_record(log_record) ⇒ Object
Formats the log record using the configured formatter and NB: Depending on the implementation of write(), this may buffer the record in memory.
51 52 53 54 55 56 57 58 |
# File 'lib/vcap/logging/sink/base_sink.rb', line 51 def add_record(log_record) raise UsageError, "You cannot add a record until the sink has been opened" unless @opened raise UsageError, "You must supply a formatter" unless @formatter = @formatter.format_record(log_record) write() flush if @autoflush end |
#close ⇒ Object
Closes any underlying file descriptors and ensures that any log records buffered in memory are flushed.
38 39 40 |
# File 'lib/vcap/logging/sink/base_sink.rb', line 38 def close @mutex.synchronize { @opened = false } end |
#flush ⇒ Object
Flushes any log records that may have been buffered in memory
61 62 63 |
# File 'lib/vcap/logging/sink/base_sink.rb', line 61 def flush nil end |
#open ⇒ Object
Opens any underlying file descriptors, etc. and ensures that the sink is capable of receiving records.
This MUST be called before any calls to add_record().
32 33 34 |
# File 'lib/vcap/logging/sink/base_sink.rb', line 32 def open @mutex.synchronize { @opened = true } end |