2013-07-29 18:26:24 -04:00
|
|
|
require 'active_support/log_subscriber'
|
|
|
|
|
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
|
|
|
|
# email is delivered and 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
|
|
|
|
recipients = Array(event.payload[:to]).join(', ')
|
|
|
|
"\nSent mail to #{recipients} (#{event.duration.round(1)}ms)"
|
|
|
|
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)
|
2014-07-18 02:27:08 -04:00
|
|
|
info { "\nReceived mail (#{event.duration.round(1)}ms)" }
|
|
|
|
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]
|
|
|
|
"\n#{mailer}##{action}: processed outbound mail in #{event.duration.round(1)}ms"
|
|
|
|
end
|
2013-10-16 04:32:06 -04:00
|
|
|
end
|
|
|
|
|
2013-05-15 00:19:38 -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
|