Class: SemanticLogger::Processor

Inherits:
Appender::Async show all
Defined in:
lib/semantic_logger/processor.rb

Overview

Thread that submits and processes log requests

Class Attribute Summary collapse

Instance Attribute Summary collapse

Attributes inherited from Appender::Async

#appender, #processor

Instance Method Summary collapse

Methods inherited from Appender::Async

#reopen

Constructor Details

#initialize(max_queue_size: 10_000) ⇒ Processor

Returns a new instance of Processor.



26
27
28
29
# File 'lib/semantic_logger/processor.rb', line 26

def initialize(max_queue_size: 10_000)
  @appenders = Appenders.new(self.class.logger.dup)
  super(appender: @appenders, max_queue_size: max_queue_size)
end

Class Attribute Details

.loggerObject

Internal logger for SemanticLogger For example when an appender is not working etc.. By default logs to $stderr



15
16
17
18
19
20
21
22
# File 'lib/semantic_logger/processor.rb', line 15

def self.logger
  @logger ||=
    begin
      l      = SemanticLogger::Appender::IO.new($stderr, level: :warn)
      l.name = name
      l
    end
end

Instance Attribute Details

#appendersObject (readonly)

Returns the value of attribute appenders.



24
25
26
# File 'lib/semantic_logger/processor.rb', line 24

def appenders
  @appenders
end

Instance Method Details

#startObject

Start the appender thread



32
33
34
35
36
37
# File 'lib/semantic_logger/processor.rb', line 32

def start
  return false if active?

  thread
  true
end

#statsObject

Returns [Hash] operational statistics for the logging pipeline.

queue_size:     [Integer] Number of log messages waiting on the main pipeline queue.
capped:         [Boolean] Whether the main queue has a maximum size.
max_queue_size: [Integer] Maximum queue size, or nil when uncapped.
thread_active:  [Boolean] Whether the main pipeline thread is running.
processed:      [Integer] Cumulative number of log messages processed since startup.
dropped:        [Integer] Cumulative number of log messages dropped at the main queue.
appenders:      [Array<Hash>] Per-appender statistics, see Appenders#stats.


48
49
50
51
52
53
54
55
56
57
58
# File 'lib/semantic_logger/processor.rb', line 48

def stats
  {
    queue_size:     queue.size,
    capped:         capped?,
    max_queue_size: capped? ? max_queue_size : nil,
    thread_active:  active? || false,
    processed:      processed_count,
    dropped:        dropped_count,
    appenders:      appenders.stats
  }
end