Class: Archfiend::Logging::MultiLogger

Inherits:
BasicObject
Defined in:
lib/archfiend/logging/multi_logger.rb

Overview

A basic class that forwards all log calls to loggers it was initialized with.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*loggers) ⇒ MultiLogger

Returns a new instance of MultiLogger.

Parameters:

  • loggers (Array<Logger>)

    A list of loggers to forward messages to



8
9
10
11
# File 'lib/archfiend/logging/multi_logger.rb', line 8

def initialize(*loggers)
  @loggers = loggers.flatten
  @responding_loggers = {}
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object (private)

Returns The return value is forwarded from the first logger that responds to the method_name.

Returns:

  • (Object)

    The return value is forwarded from the first logger that responds to the method_name



16
17
18
19
20
# File 'lib/archfiend/logging/multi_logger.rb', line 16

def method_missing(method_name, *args, &block)
  return super unless responding_loggers(method_name).any?

  responding_loggers(method_name).map { |l| l.public_send(method_name, *args, &block) }.first
end

Instance Attribute Details

#loggersObject (readonly)

Returns the value of attribute loggers.



5
6
7
# File 'lib/archfiend/logging/multi_logger.rb', line 5

def loggers
  @loggers
end