Class: RailsSemanticLogger::ActionMailer::LogSubscriber::EventFormatter

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of EventFormatter.



45
46
47
48
# 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

Instance Method Details

#dateObject



72
73
74
75
76
77
78
# 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

#payloadObject



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# 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