Class: Sidekiq::Middleware::Server::Logging

Inherits:
Object
  • Object
show all
Defined in:
lib/sidekiq/middleware/server/logging.rb

Instance Method Summary collapse

Instance Method Details

#call(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/sidekiq/middleware/server/logging.rb', line 6

def call(*args)
  Sidekiq::Logging.with_context("#{args[0].class.to_s} MSG-#{args[0].object_id.to_s(36)}") do
    begin
      start = Time.now
      logger.info { "start" }
      yield
      logger.info { "done: #{elapsed(start)} sec" }
    rescue
      logger.info { "fail: #{elapsed(start)} sec" }
      raise
    end
  end
end

#elapsed(start) ⇒ Object



20
21
22
# File 'lib/sidekiq/middleware/server/logging.rb', line 20

def elapsed(start)
  (Time.now - start).to_f.round(3)
end

#loggerObject



24
25
26
# File 'lib/sidekiq/middleware/server/logging.rb', line 24

def logger
  Sidekiq.logger
end