class GrafanaReporter::Logger::TwoWayDelegateLogger

This logger enables a special use case, so that one and the same log will automatically be send to two different logger destinations.

One destination is the set {#additional_logger=} which respects the configured severity. The other destination is an internal logger, which will always log all messages in mode Logger::Severity::Debug. All messages of the internal logger can easily be retrieved, by using the {#internal_messages} method.

Except the {#level=} setting, all calls to the logger will immediately be delegated to the internal logger and the configured {#additional_logger=}. By having this behavior, the class can be used wherever the standard Logger can also be used.

Public Class Methods

new() click to toggle source
# File lib/grafana_reporter/logger/two_way_delegate_logger.rb, line 20
def initialize
  @internal_messages = StringIO.new
  @internal_logger = ::Logger.new(@internal_messages)
  @internal_logger.level = ::Logger::Severity::DEBUG
  @additional_logger = ::Logger.new(nil)
end

Public Instance Methods

additional_logger=(logger) click to toggle source

Used to set the additional logger in this class to an already existing logger. @param logger [Logger] sets the additional logger to the given value.

# File lib/grafana_reporter/logger/two_way_delegate_logger.rb, line 41
def additional_logger=(logger)
  @additional_logger = logger || ::Logger.new(nil)
end
internal_messages() click to toggle source

@return [String] all messages of the internal logger.

# File lib/grafana_reporter/logger/two_way_delegate_logger.rb, line 34
def internal_messages
  @internal_messages.string
end
level=(severity) click to toggle source

Sets the severity level of the additional logger to the given severity. @param severity one of Logger::Severity

# File lib/grafana_reporter/logger/two_way_delegate_logger.rb, line 29
def level=(severity)
  @additional_logger.level = severity
end
method_missing(method, *args) click to toggle source

Delegates all not configured calls to the internal and the additional logger.

# File lib/grafana_reporter/logger/two_way_delegate_logger.rb, line 46
def method_missing(method, *args)
  @internal_logger.send(method, *args)
  @additional_logger.send(method, *args)
end
respond_to_missing?(method, *_args) click to toggle source

Registers all methods to which the internal logger responds.

Calls superclass method
# File lib/grafana_reporter/logger/two_way_delegate_logger.rb, line 52
def respond_to_missing?(method, *_args)
  super
  @internal_logger.respond_to?(method)
end