Class: NRSER::Log::Appender::Sync
- Extended by:
- Forwardable
- Defined in:
- lib/nrser/log/appender/sync.rb
Overview
Replacement for SemanticLogger::Appender::Async that implements the same interface but just logs synchronously in the current thread.
Basically just implements the SemanticLogger::Appender::Async API, returning mostly with fake / nonsense values, but it seems to work, and just let’s writes go strait through to the #appender (which is actually a SemanticLogger::Processor).
Useful for CLI applications where you want to see output in sync with operations.
Defined Under Namespace
Classes: FakeQueue
Instance Attribute Summary collapse
-
#appender ⇒ SemanticLogger::Processor
The appender we forward to, which is a SemanticLogger::Processor in practice, since it wouldn’t make any sense to wrap a regular appender in a Sync.
Instance Method Summary collapse
-
#active? ⇒ true
Sync appender is always active.
-
#capped? ⇒ false
Sync appender is of course not size-capped.
-
#initialize(appender:, name: appender.class.safe_name) ⇒ Sync
constructor
Construct a sync appender.
-
#lag_check_interval ⇒ -1
Nonsense value meant to indicate there is no lag check interval.
- #lag_check_interval=(value) ⇒ Object
-
#lag_threshold_s ⇒ -1
Nonsense value meant to indicate there is no lag threshold.
- #lag_threshold_s=(value) ⇒ Object
-
#queue ⇒ #size
Needs to be there to support SemanticLogger::Processor.queue_size, which gets the queue and returns it’s size (which will always be zero for us).
-
#thread ⇒ nil
The SemanticLogger::Appender::Async worker thread is exposed via this method, which creates it if it doesn’t exist and returns it, but it doesn’t seem like the returned value is ever used; the method call is just invoked to start the thread.
Constructor Details
#initialize(appender:, name: appender.class.safe_name) ⇒ Sync
Construct a sync appender.
87 88 89 |
# File 'lib/nrser/log/appender/sync.rb', line 87 def initialize appender:, name: appender.class.safe_name @appender = appender end |
Instance Attribute Details
#appender ⇒ SemanticLogger::Processor
The appender we forward to, which is a SemanticLogger::Processor in practice, since it wouldn’t make any sense to wrap a regular appender in a Sync.
37 38 39 |
# File 'lib/nrser/log/appender/sync.rb', line 37 def appender @appender end |
Instance Method Details
#active? ⇒ true
Returns Sync appender is always active.
150 |
# File 'lib/nrser/log/appender/sync.rb', line 150 def active?; true; end |
#capped? ⇒ false
Returns Sync appender is of course not size-capped.
131 |
# File 'lib/nrser/log/appender/sync.rb', line 131 def capped?; false; end |
#lag_check_interval ⇒ -1
Returns Nonsense value meant to indicate there is no lag check interval.
105 |
# File 'lib/nrser/log/appender/sync.rb', line 105 def lag_check_interval; -1; end |
#lag_check_interval=(value) ⇒ Object
110 111 112 113 |
# File 'lib/nrser/log/appender/sync.rb', line 110 def lag_check_interval= value raise NotImplementedError, "Can't set `lag_check_interval` on Sync appender" end |
#lag_threshold_s ⇒ -1
Returns Nonsense value meant to indicate there is no lag threshold.
118 |
# File 'lib/nrser/log/appender/sync.rb', line 118 def lag_threshold_s; -1; end |
#lag_threshold_s=(value) ⇒ Object
123 124 125 126 |
# File 'lib/nrser/log/appender/sync.rb', line 123 def lag_threshold_s= value raise NotImplementedError, "Can't set `lag_threshold_s` on Sync appender" end |
#queue ⇒ #size
Needs to be there to support SemanticLogger::Processor.queue_size, which gets the queue and returns it’s size (which will always be zero for us).
We return FakeQueue, which only implements a ‘size` method that returns zero.
100 |
# File 'lib/nrser/log/appender/sync.rb', line 100 def queue; FakeQueue; end |
#thread ⇒ nil
The SemanticLogger::Appender::Async worker thread is exposed via this method, which creates it if it doesn’t exist and returns it, but it doesn’t seem like the returned value is ever used; the method call is just invoked to start the thread.
Hence it seems to make most sense to just return ‘nil` since we don’t have a thread, and figure out what to do if that causes errors (so far it seems fine).
145 |
# File 'lib/nrser/log/appender/sync.rb', line 145 def thread; end |