Class: Logcraft::Sidekiq::JobLogger
- Inherits:
-
Object
- Object
- Logcraft::Sidekiq::JobLogger
- Includes:
- LogContextHelper
- Defined in:
- lib/logcraft/sidekiq/job_logger.rb
Instance Method Summary collapse
- #call(job_hash, _queue) ⇒ Object
-
#initialize(config_or_logger = ::Sidekiq.logger) ⇒ JobLogger
constructor
A new instance of JobLogger.
- #prepare(_job_hash, &_block) ⇒ Object
Constructor Details
#initialize(config_or_logger = ::Sidekiq.logger) ⇒ JobLogger
Returns a new instance of JobLogger.
8 9 10 11 12 13 14 |
# File 'lib/logcraft/sidekiq/job_logger.rb', line 8 def initialize(config_or_logger = ::Sidekiq.logger) @logger = if config_or_logger.respond_to? :logger config_or_logger.logger else config_or_logger end end |
Instance Method Details
#call(job_hash, _queue) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/logcraft/sidekiq/job_logger.rb', line 16 def call(job_hash, _queue) within_log_context(JobContext.from_job_hash(job_hash)) do begin @logger.info "#{job_hash['class']} started" benchmark { yield } @logger.info message: "#{job_hash['class']} finished" rescue Exception @logger.info message: "#{job_hash['class']} failed" raise end end end |
#prepare(_job_hash, &_block) ⇒ Object
29 30 31 |
# File 'lib/logcraft/sidekiq/job_logger.rb', line 29 def prepare(_job_hash, &_block) yield end |