Class: RailsSemanticLogger::Sidekiq::JobLogger
- Inherits:
-
Object
- Object
- RailsSemanticLogger::Sidekiq::JobLogger
- Defined in:
- lib/rails_semantic_logger/sidekiq/job_logger.rb
Constant Summary collapse
- DEFAULT_LOGGED_JOB_ATTRIBUTES =
Job attributes copied into the logging context, matching Sidekiq's own defaults. Sidekiq 8 makes this configurable via
config[:logged_job_attributes]. %w[bid tags].freeze
Class Attribute Summary collapse
Instance Method Summary collapse
- #call(item, queue, &block) ⇒ Object
-
#initialize(arg = nil) ⇒ JobLogger
constructor
Sidekiq 7 passes its logger, whereas Sidekiq 8 passes its config.
- #prepare(job_hash, &block) ⇒ Object
Constructor Details
#initialize(arg = nil) ⇒ JobLogger
Sidekiq 7 passes its logger, whereas Sidekiq 8 passes its config.
17 18 19 |
# File 'lib/rails_semantic_logger/sidekiq/job_logger.rb', line 17 def initialize(arg = nil) @config = arg if arg.respond_to?(:[]) end |
Class Attribute Details
.perform_messages ⇒ Object
11 12 13 |
# File 'lib/rails_semantic_logger/sidekiq/job_logger.rb', line 11 def instance_variable_defined?(:@perform_messages) ? @perform_messages : true end |
Instance Method Details
#call(item, queue, &block) ⇒ Object
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 48 |
# File 'lib/rails_semantic_logger/sidekiq/job_logger.rb', line 21 def call(item, queue, &block) klass = item["wrapped"] || item["class"] logger = klass ? SemanticLogger[klass] : Sidekiq.logger SemanticLogger.tagged(queue: queue) do if # Latency is the time between when the job was enqueued and when it started executing. logger.info( "Start #perform", metric: "sidekiq.queue.latency", metric_amount: job_latency_ms(item) ) end # Measure the duration of running the job if logger.measure_info( "Completed #perform", on_exception_level: :error, log_exception: :full, metric: "sidekiq.job.perform", &block ) elsif block_given? yield end end end |
#prepare(job_hash, &block) ⇒ Object
50 51 52 53 54 55 56 57 58 59 |
# File 'lib/rails_semantic_logger/sidekiq/job_logger.rb', line 50 def prepare(job_hash, &block) level = job_hash["log_level"] if level SemanticLogger.silence(level) do SemanticLogger.tagged(job_hash_context(job_hash), &block) end else SemanticLogger.tagged(job_hash_context(job_hash), &block) end end |