Skip to content

Commit

Permalink
Merge pull request sidekiq#2485 from grosser/grosser/logs
Browse files Browse the repository at this point in the history
small refactor for Logging middleware
  • Loading branch information
mperham committed Aug 12, 2015
2 parents a7696ef + 8dd5361 commit 7fb504a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/sidekiq/middleware/server/logging.rb
Expand Up @@ -4,11 +4,7 @@ module Server
class Logging

def call(worker, item, queue)
# If we're using a wrapper class, like ActiveJob, use the "wrapped"
# attribute to expose the underlying thing.
klass = item['wrapped'] || worker.class.to_s

Sidekiq::Logging.with_context("#{klass} JID-#{item['jid']}#{" BID-#{item['bid']}" if item['bid']}") do
Sidekiq::Logging.with_context(log_context(worker, item)) do
begin
start = Time.now
logger.info { "start" }
Expand All @@ -21,6 +17,15 @@ def call(worker, item, queue)
end
end

private

# If we're using a wrapper class, like ActiveJob, use the "wrapped"
# attribute to expose the underlying thing.
def log_context(worker, item)
klass = item['wrapped'.freeze] || worker.class.to_s
"#{klass} JID-#{item['jid'.freeze]}#{" BID-#{item['bid'.freeze]}" if item['bid'.freeze]}"
end

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

0 comments on commit 7fb504a

Please sign in to comment.