Sha256: ad42ca4040a3e49f7580bee773fb430ca9fdb206a2f25c237d3764cd00ec49e4
Contents?: true
Size: 1.17 KB
Versions: 1
Compression:
Stored size: 1.17 KB
Contents
require 'active_support/log_subscriber' module LogrageActivejob class LogSubscriber < ActiveSupport::LogSubscriber def perform(event) data = initial_data(event) data.merge!(custom_options(event)) formatted_message = Lograge.formatter.call(data) logger.send(Lograge.log_level, formatted_message) end private def logger Lograge.logger.presence || super end def initial_data(event) payload = event.payload job = payload[:job] ex = payload[:exception_object] { event_name: event.name, job_class: job.class.name, job_id: job.job_id, adapter_class: event.payload[:adapter].class.name.demodulize, queue_name: job.queue_name, args: job.arguments, duration: event.duration.round(2), # ms message: ex&.message, # deprecated in v0.3.0 error: ex&.message, backtrace: ex&.backtrace, }.compact end def custom_options(event) LogrageActivejob.custom_options(event) || {} end def scheduled_at(job) Time.at(job.scheduled_at).utc if job.scheduled_at end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
lograge_activejob-0.2.0 | lib/lograge_activejob/log_subscriber.rb |