class RailsSemanticLogger::ActiveJob::LogSubscriber

Public Instance Methods

enqueue(event) click to toggle source
# File lib/rails_semantic_logger/active_job/log_subscriber.rb, line 6
def enqueue(event)
  ex = event.payload[:exception_object]

  if ex
    log_with_formatter level: :error, event: event do |fmt|
      {
        message:   "Failed enqueuing #{fmt.job_info} (#{ex.class} (#{ex.message})",
        exception: ex
      }
    end
  elsif event.payload[:aborted]
    log_with_formatter level: :info, event: event do |fmt|
      {message: "Failed enqueuing #{fmt.job_info}, a before_enqueue callback halted the enqueuing execution."}
    end
  else
    log_with_formatter event: event do |fmt|
      {message: "Enqueued #{fmt.job_info}"}
    end
  end
end
enqueue_at(event) click to toggle source
# File lib/rails_semantic_logger/active_job/log_subscriber.rb, line 27
def enqueue_at(event)
  ex = event.payload[:exception_object]

  if ex
    log_with_formatter level: :error, event: event do |fmt|
      {
        message:   "Failed enqueuing #{fmt.job_info} (#{ex.class} (#{ex.message})",
        exception: ex
      }
    end
  elsif event.payload[:aborted]
    log_with_formatter level: :info, event: event do |fmt|
      {message: "Failed enqueuing #{fmt.job_info}, a before_enqueue callback halted the enqueuing execution."}
    end
  else
    log_with_formatter event: event do |fmt|
      {message: "Enqueued #{fmt.job_info} at #{fmt.scheduled_at}"}
    end
  end
end
perform(event) click to toggle source
# File lib/rails_semantic_logger/active_job/log_subscriber.rb, line 54
def perform(event)
  ex = event.payload[:exception_object]
  if ex
    log_with_formatter event: event, log_duration: true, level: :error do |fmt|
      {
        message:   "Error performing #{fmt.job_info} in #{event.duration.round(2)}ms",
        exception: ex
      }
    end
  else
    log_with_formatter event: event, log_duration: true do |fmt|
      {message: "Performed #{fmt.job_info} in #{event.duration.round(2)}ms"}
    end
  end
end
perform_start(event) click to toggle source
# File lib/rails_semantic_logger/active_job/log_subscriber.rb, line 48
def perform_start(event)
  log_with_formatter event: event do |fmt|
    {message: "Performing #{fmt.job_info}"}
  end
end

Private Instance Methods

log_with_formatter(level: :info, **kw_args) { |fmt| ... } click to toggle source
# File lib/rails_semantic_logger/active_job/log_subscriber.rb, line 145
def log_with_formatter(level: :info, **kw_args)
  fmt = EventFormatter.new(**kw_args)
  msg = yield fmt
  logger.public_send(level, **msg, payload: fmt.payload)
end
logger() click to toggle source
# File lib/rails_semantic_logger/active_job/log_subscriber.rb, line 151
def logger
  ::ActiveJob::Base.logger
end