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:

  • appender (SemanticLogger::Subscriber)

    The appender this appender will attempt to append to when there are

    pending appendables to append. Apparently.

    Sorry, I just ended up here trying to clear out Yard warnings so I can maybe figure out why it’s all of sudden shitting the bed. Guess I needed a break.

    In truth I don’t even think it needs to be a Subscriber, but that’s probably the easiest way to think about it.

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

    Name to use for the log thread and the log name when logging any errors from this 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

#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



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.

Returns:

  • (false)

    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.

Returns:

  • (-1)

    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

Raises:

  • (NotImplementedError)

    Sync appender doesn’t support setting lag check interval.



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.

Returns:

  • (-1)

    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

Raises:

  • (NotImplementedError)

    Sync appender doesn’t support setting log threshold.



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.

Returns:

  • (#size)


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

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)


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

def thread; end