Class: SemanticLogger::SyncProcessor
- Inherits:
-
Object
- Object
- SemanticLogger::SyncProcessor
- Defined in:
- lib/semantic_logger/sync_processor.rb
Overview
The SyncProcessor performs logging in the current thread.
Appenders are designed to only be used by one thread at a time, so all calls are monitor protected in case SyncProcessor is being used in a multi-threaded environment.
Class Attribute Summary collapse
-
.logger ⇒ Object
Internal logger for SemanticLogger For example when an appender is not working etc..
Instance Attribute Summary collapse
-
#appenders ⇒ Object
readonly
Returns the value of attribute appenders.
Instance Method Summary collapse
- #add ⇒ Object
- #close ⇒ Object
- #flush ⇒ Object
-
#initialize(appenders = nil) ⇒ SyncProcessor
constructor
A new instance of SyncProcessor.
- #log ⇒ Object
- #reopen(*args) ⇒ Object
- #start ⇒ Object
-
#stats ⇒ Object
Returns [Hash] operational statistics for the logging pipeline.
Constructor Details
#initialize(appenders = nil) ⇒ SyncProcessor
Returns a new instance of SyncProcessor.
70 71 72 73 74 |
# File 'lib/semantic_logger/sync_processor.rb', line 70 def initialize(appenders = nil) @monitor = Monitor.new @appenders = appenders || Appenders.new(self.class.logger.dup) @processed_count = 0 end |
Class Attribute Details
.logger ⇒ Object
Internal logger for SemanticLogger For example when an appender is not working etc.. By default logs to $stderr
59 60 61 62 63 64 65 66 |
# File 'lib/semantic_logger/sync_processor.rb', line 59 def self.logger @logger ||= begin l = SemanticLogger::Appender::IO.new($stderr, level: :warn) l.name = name l end end |
Instance Attribute Details
#appenders ⇒ Object (readonly)
Returns the value of attribute appenders.
68 69 70 |
# File 'lib/semantic_logger/sync_processor.rb', line 68 def appenders @appenders end |
Instance Method Details
#add ⇒ Object
7 8 9 |
# File 'lib/semantic_logger/sync_processor.rb', line 7 def add(...) @monitor.synchronize { @appenders.add(...) } end |
#close ⇒ Object
40 41 42 |
# File 'lib/semantic_logger/sync_processor.rb', line 40 def close @monitor.synchronize { @appenders.close } end |
#flush ⇒ Object
36 37 38 |
# File 'lib/semantic_logger/sync_processor.rb', line 36 def flush @monitor.synchronize { @appenders.flush } end |
#log ⇒ Object
11 12 13 14 15 16 |
# File 'lib/semantic_logger/sync_processor.rb', line 11 def log(...) @monitor.synchronize do @processed_count += 1 @appenders.log(...) end end |
#reopen(*args) ⇒ Object
44 45 46 |
# File 'lib/semantic_logger/sync_processor.rb', line 44 def reopen(*args) @monitor.synchronize { @appenders.reopen(*args) } end |
#start ⇒ Object
76 77 78 |
# File 'lib/semantic_logger/sync_processor.rb', line 76 def start # NOP end |
#stats ⇒ Object
Returns [Hash] operational statistics for the logging pipeline.
In synchronous mode there is no queue: messages are written inline on the calling thread, so queue_size is always 0 and no messages can be dropped.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/semantic_logger/sync_processor.rb', line 22 def stats @monitor.synchronize do { queue_size: 0, capped: false, max_queue_size: nil, thread_active: false, processed: @processed_count, dropped: 0, appenders: @appenders.stats } end end |