Module: Sidekiq::Logging::Shared
- Included in:
- Sidekiq::LogstashJobLogger
- Defined in:
- lib/sidekiq/logging/shared.rb
Overview
Shared module with all the logics used by job loggers.
Constant Summary collapse
- ENCRYPTED =
'[ENCRYPTED]'
Instance Method Summary collapse
- #log_job(job) ⇒ Object
- #log_job_exception(job, started_at, exc) ⇒ Object
- #log_job_exec(job, started_at) ⇒ Object
- #log_job_start(job) ⇒ Object
Instance Method Details
#log_job(job) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sidekiq/logging/shared.rb', line 11 def log_job(job) started_at = Time.now.utc log_start = log_job_start(job) Sidekiq.logger.info log_start if log_start yield if block_given? Sidekiq.logger.info log_job_exec(job, started_at) rescue StandardError => e begin Sidekiq.logger.warn log_job_exception(job, started_at, e) rescue StandardError => e log_standard_error(job, e, e) end raise end |
#log_job_exception(job, started_at, exc) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/sidekiq/logging/shared.rb', line 48 def log_job_exception(job, started_at, exc) payload = setup_payload(job) payload['duration'] = elapsed(started_at) payload['message'] += ": fail: #{payload['duration']} sec" payload['job_status'] = 'fail' config = Sidekiq::Logstash.configuration if config.log_job_exception_with_causes payload['error'] = Sidekiq::Logging::ExceptionUtils.get_exception_with_cause_hash( exc, max_depth_left: config.causes_logging_max_depth ) else exc = exc.cause || exc if exc.is_a? Sidekiq::JobRetry::Handled payload['error_message'] = exc. payload['error'] = exc.class.to_s payload['error_backtrace'] = %('#{exc.backtrace.join("\n")}') if (cause = exc.cause) payload['error_cause'] = { 'class' => cause.class.to_s, 'message' => cause., 'backtrace' => Sidekiq::Logging::ExceptionUtils.backtrace_for(cause, exc.backtrace) } end end process_payload(payload) end |
#log_job_exec(job, started_at) ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sidekiq/logging/shared.rb', line 37 def log_job_exec(job, started_at) payload = setup_payload(job) payload['duration'] = elapsed(started_at) payload['message'] += ": done: #{payload['duration']} sec" payload['job_status'] = 'done' payload['completed_at'] = Time.now.utc process_payload(payload) end |
#log_job_start(job) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sidekiq/logging/shared.rb', line 26 def log_job_start(job) return unless Sidekiq::Logstash.configuration.job_start_log # Skips start logs for retrying jobs return if job['failed_at'] payload = setup_payload(job) payload['job_status'] = 'started' payload['message'] += ': started' process_payload(payload) end |