2017-07-23 11:17:16 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 13:01:31 -04:00
|
|
|
require "active_support/log_subscriber"
|
2013-07-29 18:26:24 -04:00
|
|
|
|
2013-05-19 11:36:06 -04:00
|
|
|
module ActionMailer
|
2013-05-15 00:19:38 -04:00
|
|
|
# Implements the ActiveSupport::LogSubscriber for logging notifications when
|
2015-05-29 13:50:12 -04:00
|
|
|
# email is delivered or received.
|
2010-06-24 07:23:43 -04:00
|
|
|
class LogSubscriber < ActiveSupport::LogSubscriber
|
2013-05-15 00:19:38 -04:00
|
|
|
# An email was delivered.
|
2010-06-24 07:23:43 -04:00
|
|
|
def deliver(event)
|
2014-07-18 02:27:08 -04:00
|
|
|
info do
|
2016-08-06 13:01:31 -04:00
|
|
|
recipients = Array(event.payload[:to]).join(", ")
|
2015-10-26 10:58:18 -04:00
|
|
|
"Sent mail to #{recipients} (#{event.duration.round(1)}ms)"
|
2014-07-18 02:27:08 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
debug { event.payload[:mail] }
|
2010-06-24 07:23:43 -04:00
|
|
|
end
|
|
|
|
|
2013-05-15 00:19:38 -04:00
|
|
|
# An email was received.
|
2010-06-24 07:23:43 -04:00
|
|
|
def receive(event)
|
2015-10-26 10:58:18 -04:00
|
|
|
info { "Received mail (#{event.duration.round(1)}ms)" }
|
2014-07-18 02:27:08 -04:00
|
|
|
debug { event.payload[:mail] }
|
2010-06-24 07:23:43 -04:00
|
|
|
end
|
|
|
|
|
2013-10-16 04:32:06 -04:00
|
|
|
# An email was generated.
|
|
|
|
def process(event)
|
2014-07-18 02:27:08 -04:00
|
|
|
debug do
|
|
|
|
mailer = event.payload[:mailer]
|
|
|
|
action = event.payload[:action]
|
2015-10-26 10:58:18 -04:00
|
|
|
"#{mailer}##{action}: processed outbound mail in #{event.duration.round(1)}ms"
|
2014-07-18 02:27:08 -04:00
|
|
|
end
|
2013-10-16 04:32:06 -04:00
|
|
|
end
|
|
|
|
|
2015-09-28 11:47:44 -04:00
|
|
|
# Use the logger configured for ActionMailer::Base.
|
2010-06-24 07:23:43 -04:00
|
|
|
def logger
|
|
|
|
ActionMailer::Base.logger
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-01-05 14:24:48 -05:00
|
|
|
ActionMailer::LogSubscriber.attach_to :action_mailer
|