Class: Julewire::SemanticLogger::AsyncOptions

Inherits:
Object
  • Object
show all
Defined in:
lib/julewire/semantic_logger/async_options.rb

Constant Summary collapse

DEFAULT_MAX_QUEUE_SIZE =
10_000
DEFAULTS =
{
  max_queue_size: DEFAULT_MAX_QUEUE_SIZE,
  lag_check_interval: 1_000,
  lag_threshold_s: 30,
  batch: nil,
  batch_size: 300,
  batch_seconds: 5,
  non_blocking: false,
  dropped_message_report_seconds: 30,
  async_max_retries: 100
}.freeze
BATCH_OPTIONS =
{ batch_size: true, batch_seconds: true }.freeze
KEYWORD_PARAMETER_KINDS =
{ key: true, keyreq: true }.freeze
SUPPORTED_DEFAULTS =
DEFAULTS.keys.to_h { [it, true] }.freeze
ASYNC_APPENDER =
::SemanticLogger::Appender::Async
ASYNC_APPENDER_ACCEPTS_ANY_KEYWORD =
ASYNC_APPENDER.instance_method(:initialize).parameters.any? { |kind, _name| kind == :keyrest }
ASYNC_BATCH_APPENDER =
if ::SemanticLogger::Appender.const_defined?(:AsyncBatch, false)
  ::SemanticLogger::Appender.const_get(:AsyncBatch, false)
end

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values:, configured:) ⇒ AsyncOptions

Returns a new instance of AsyncOptions.



44
45
46
47
# File 'lib/julewire/semantic_logger/async_options.rb', line 44

def initialize(values:, configured:)
  @values = values
  @configured = configured
end

Class Method Details

.extract(options) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/julewire/semantic_logger/async_options.rb', line 29

def extract(options)
  configured = []
  values = DEFAULTS.to_h do |name, default|
    if options.key?(name)
      configured << name
      [name, options.delete(name)]
    else
      [name, default]
    end
  end

  new(values: values, configured: configured)
end

Instance Method Details

#async?(base_async) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/julewire/semantic_logger/async_options.rb', line 49

def async?(base_async)
  base_async || batch_enabled?
end

#build_appender(sink) ⇒ Object



57
58
59
60
# File 'lib/julewire/semantic_logger/async_options.rb', line 57

def build_appender(sink)
  klass = appender_class
  klass.new(appender: sink, **constructor_options(klass))
end

#max_queue_sizeObject



53
54
55
# File 'lib/julewire/semantic_logger/async_options.rb', line 53

def max_queue_size
  @values.fetch(:max_queue_size)
end