Class: RailsSemanticLogger::ActiveJob::LogSubscriber::EventFormatter
- Inherits:
-
Object
- Object
- RailsSemanticLogger::ActiveJob::LogSubscriber::EventFormatter
- Defined in:
- lib/rails_semantic_logger/active_job/log_subscriber.rb
Instance Method Summary collapse
-
#initialize(event:, log_duration: false) ⇒ EventFormatter
constructor
A new instance of EventFormatter.
- #job_info ⇒ Object
- #payload ⇒ Object
- #queue_name ⇒ Object
- #scheduled_at ⇒ Object
Constructor Details
#initialize(event:, log_duration: false) ⇒ EventFormatter
Returns a new instance of EventFormatter.
43 44 45 46 |
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 43 def initialize(event:, log_duration: false) @event = event @log_duration = log_duration end |
Instance Method Details
#job_info ⇒ Object
48 49 50 |
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 48 def job_info "#{job.class.name} (Job ID: #{job.job_id}) to #{queue_name}" end |
#payload ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 52 def payload {}.tap do |h| h[:event_name] = event.name h[:adapter] = adapter_name h[:queue] = job.queue_name h[:job_class] = job.class.name h[:job_id] = job.job_id h[:provider_job_id] = job.try(:provider_job_id) # Not available in Rails 4.2 h[:duration] = event.duration.round(2) if log_duration? h[:arguments] = formatted_args end end |
#queue_name ⇒ Object
65 66 67 |
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 65 def queue_name adapter_name + "(#{job.queue_name})" end |
#scheduled_at ⇒ Object
69 70 71 |
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 69 def scheduled_at Time.at(event.payload[:job].scheduled_at).utc end |