Class: NRSER::Log::Appender::Sync

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(appender:, name: appender.class.safe_name) ⇒ Sync

Construct a sync appender.

Parameters:

  • name: (SemanticLogger) (defaults to: appender.class.safe_name)
    String

    Name to use for the log thread and the log name when logging any errors from this appender.

    lag_threshold_s [Float]

    Log a warning when a log message has been on the queue for longer than this period in seconds.
    Default: 30
    

    lag_check_interval: [Integer]

    Number of messages to process before checking for slow logging.
    Default: 1,000
    


83
84
85
# File 'lib/nrser/log/appender/sync.rb', line 83

def initialize  appender:, name: appender.class.safe_name
  @appender = appender
end

Instance Attribute Details

#appenderSemanticLogger::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.

Returns:

  • (SemanticLogger::Processor)


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.

Returns:

  • (true)

    Sync appender is always active



146
# File 'lib/nrser/log/appender/sync.rb', line 146

def active?; true; end

#capped?false

Returns Sync appender is of course not size-capped.

Returns:

  • (false)

    Sync appender is of course not size-capped.



127
# File 'lib/nrser/log/appender/sync.rb', line 127

def capped?; false; end

#lag_check_interval-1

Returns Nonsense value meant to indicate there is no lag check interval.

Returns:

  • (-1)

    Nonsense value meant to indicate there is no lag check interval.



101
# File 'lib/nrser/log/appender/sync.rb', line 101

def lag_check_interval; -1; end

#lag_check_interval=(value) ⇒ Object

Raises:

  • (NotImplementedError)

    Sync appender doesn’t support setting lag check interval.



106
107
108
109
# File 'lib/nrser/log/appender/sync.rb', line 106

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.

Returns:

  • (-1)

    Nonsense value meant to indicate there is no lag threshold.



114
# File 'lib/nrser/log/appender/sync.rb', line 114

def lag_threshold_s; -1; end

#lag_threshold_s=(value) ⇒ Object

Raises:

  • (NotImplementedError)

    Sync appender doesn’t support setting log threshold.



119
120
121
122
# File 'lib/nrser/log/appender/sync.rb', line 119

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.

Returns:

  • (#size)


96
# File 'lib/nrser/log/appender/sync.rb', line 96

def queue; FakeQueue; end

#threadnil

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).

Returns:

  • (nil)


141
# File 'lib/nrser/log/appender/sync.rb', line 141

def thread; end