Class: Log4rExceptionable::SidekiqFailureHandler

Inherits:
Object
  • Object
show all
Includes:
Helper
Defined in:
lib/log4r-exceptionable/sidekiq_failure_handler.rb

Overview

A Resque Failure backend that logs exceptions with log4r

Instance Method Summary collapse

Methods included from Helper

#add_context, #log_with_context

Instance Method Details

#call(worker, msg, queue) ⇒ Object



10
11
12
13
14
15
16
17
# File 'lib/log4r-exceptionable/sidekiq_failure_handler.rb', line 10

def call(worker, msg, queue)
  begin
    yield
  rescue => ex
    log_exception(worker, queue, ex, msg)
    raise
  end
end

#log_exception(worker, queue, ex, msg) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/log4r-exceptionable/sidekiq_failure_handler.rb', line 19

def log_exception(worker, queue, ex, msg)
  
  log_with_context do |context|
    
    add_context(context, "sidekiq_worker", worker.class)
    add_context(context, "sidekiq_queue", queue.to_s)
    add_context(context, "sidekiq_args", msg['args'])
    add_context(context, "sidekiq_jid", worker.jid)
    
    # add in any extra payload data
    msg.each do |k, v|
      next if %w[class args].include?(k)
      add_context(context, "sidekiq_msg_#{k}", v)
    end

    error_logger = nil
    if Log4rExceptionable::Configuration.use_source_logger
      payload_class = worker.logger rescue nil
      if worker.logger.instance_of?(Log4r::Logger)
        error_logger = worker.logger
      end
    end
    
    error_logger ||= Log4rExceptionable::Configuration.sidekiq_failure_logger
    
    error_logger.send(Log4rExceptionable::Configuration.log_level, ex)
  end
  
end