class RailsSemanticLogger::ActionMailer::LogSubscriber::EventFormatter
Attributes
event[R]
Public Class Methods
new(event:, log_duration: false)
click to toggle source
# File lib/rails_semantic_logger/action_mailer/log_subscriber.rb, line 45 def initialize(event:, log_duration: false) @event = event @log_duration = log_duration end
Public Instance Methods
date()
click to toggle source
# File lib/rails_semantic_logger/action_mailer/log_subscriber.rb, line 72 def date if event.payload[:date].respond_to?(:to_time) event.payload[:date].to_time.utc elsif event.payload[:date].is_a?(String) Time.parse(date).utc end end
mailer()
click to toggle source
# File lib/rails_semantic_logger/action_mailer/log_subscriber.rb, line 50 def mailer event.payload[:mailer] end
payload()
click to toggle source
# File lib/rails_semantic_logger/action_mailer/log_subscriber.rb, line 54 def payload {}.tap do |h| h[:event_name] = event.name h[:mailer] = mailer h[:action] = action h[:message_id] = event.payload[:message_id] h[:perform_deliveries] = event.payload[:perform_deliveries] h[:subject] = event.payload[:subject] h[:to] = event.payload[:to] h[:from] = event.payload[:from] h[:bcc] = event.payload[:bcc] h[:cc] = event.payload[:cc] h[:date] = date h[:duration] = event.duration.round(2) if log_duration? h[:args] = formatted_args end end
Private Instance Methods
action()
click to toggle source
# File lib/rails_semantic_logger/action_mailer/log_subscriber.rb, line 88 def action event.payload[:action] end
format(arg)
click to toggle source
# File lib/rails_semantic_logger/action_mailer/log_subscriber.rb, line 100 def format(arg) case arg when Hash arg.transform_values { |value| format(value) } when Array arg.map { |value| format(value) } when GlobalID::Identification begin arg.to_global_id rescue StandardError arg end else arg end end
formatted_args()
click to toggle source
# File lib/rails_semantic_logger/action_mailer/log_subscriber.rb, line 92 def formatted_args if defined?(mailer.constantize.log_arguments?) && !mailer.constantize.log_arguments? "" elsif event.payload[:args].present? JSON.pretty_generate(event.payload[:args].map { |arg| format(arg) }) end end
log_duration?()
click to toggle source
# File lib/rails_semantic_logger/action_mailer/log_subscriber.rb, line 117 def log_duration? @log_duration end