Class: RailsSemanticLogger::ActiveJob::LogSubscriber::EventFormatter

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_semantic_logger/active_job/log_subscriber.rb

Instance Method Summary collapse

Constructor Details

#initialize(event:, log_duration: false) ⇒ EventFormatter

Returns a new instance of EventFormatter.



264
265
266
267
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 264

def initialize(event:, log_duration: false)
  @event = event
  @log_duration = log_duration
end

Instance Method Details

#executionsObject



299
300
301
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 299

def executions
  job.executions
end

#job_infoObject



269
270
271
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 269

def job_info
  "#{job.class.name} (Job ID: #{job.job_id}) to #{queue_name}"
end

#payloadObject

Standard payload shared by every event. enqueued_at, scheduled_at, and duration are only present when applicable (the job was scheduled, has been enqueued, or the event carries a duration), so that handlers that do not have them never emit blank keys.



276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 276

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.provider_job_id
    h[:enqueued_at]     = job.enqueued_at if job.respond_to?(:enqueued_at) && job.enqueued_at.present?
    h[:scheduled_at]    = scheduled_at if job.scheduled_at
    h[:duration]        = event.duration.round(2) if log_duration?
    h[:arguments]       = formatted_args
  end
end

#queue_nameObject



291
292
293
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 291

def queue_name
  adapter_name + "(#{job.queue_name})"
end

#scheduled_atObject



295
296
297
# File 'lib/rails_semantic_logger/active_job/log_subscriber.rb', line 295

def scheduled_at
  Time.at(job.scheduled_at).utc
end