Class: Log::Dispatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/log/dispatcher.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(loggers) ⇒ Dispatcher

Returns a new instance of Dispatcher.



11
12
13
14
# File 'lib/log/dispatcher.rb', line 11

def initialize(loggers)
  Dispatcher.verify_loggers(config.loggers)
  @loggers = loggers
end

Instance Attribute Details

#raise_on_log_failureObject

Returns the value of attribute raise_on_log_failure.



5
6
7
# File 'lib/log/dispatcher.rb', line 5

def raise_on_log_failure
  @raise_on_log_failure
end

Class Method Details

.dispatch(severity, message, context = {}, events = []) ⇒ Object



7
8
9
# File 'lib/log/dispatcher.rb', line 7

def self.dispatch(severity, message, context = {}, events = [])
  Dispatcher.new(Log.config.loggers).dispatch(severity, message, context, events)
end

Instance Method Details

#dispatch(severity, message, context = {}, events = []) ⇒ Object

Raises:

  • (ArgumentError)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/log/dispatcher.rb', line 16

def dispatch(severity, message, context={}, events=[])
  raise ArgumentError.new("context must be Hash") unless context.kind_of?(Hash)

  failed_loggers = {}
   = {}
  @loggers.each do |logger|
    begin
      result = logger.log(severity, message, context, events, )
      .merge!(result) if (result.kind_of?(Hash))
    rescue => e
      failed_loggers[logger.name] = e
    end
  end

  handle_failed_loggers(failed_loggers)
end