Class: Sidekiq::JobLogger
- Inherits:
-
Object
- Object
- Sidekiq::JobLogger
- Defined in:
- lib/sidekiq/job_logger.rb
Instance Method Summary collapse
- #call(item, queue) ⇒ Object
-
#initialize(config) ⇒ JobLogger
constructor
A new instance of JobLogger.
- #prepare(job_hash, &block) ⇒ Object
Constructor Details
#initialize(config) ⇒ JobLogger
Returns a new instance of JobLogger.
5 6 7 8 9 |
# File 'lib/sidekiq/job_logger.rb', line 5 def initialize(config) @config = config @logger = @config.logger @skip = !!@config[:skip_default_job_logging] end |
Instance Method Details
#call(item, queue) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/sidekiq/job_logger.rb', line 11 def call(item, queue) start = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) @logger.info { "start" } unless @skip yield Sidekiq::Context.add(:elapsed, elapsed(start)) @logger.info { "done" } unless @skip rescue Exception Sidekiq::Context.add(:elapsed, elapsed(start)) @logger.info { "fail" } unless @skip raise end |
#prepare(job_hash, &block) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sidekiq/job_logger.rb', line 25 def prepare(job_hash, &block) # If we're using a wrapper class, like ActiveJob, use the "wrapped" # attribute to expose the underlying thing. h = { class: job_hash["display_class"] || job_hash["wrapped"] || job_hash["class"], jid: job_hash["jid"] } h[:bid] = job_hash["bid"] if job_hash.has_key?("bid") h[:tags] = job_hash["tags"] if job_hash.has_key?("tags") Thread.current[:sidekiq_context] = h level = job_hash["log_level"] if level && @logger.respond_to?(:log_at) @logger.log_at(level, &block) else yield end ensure Thread.current[:sidekiq_context] = nil end |