2013-05-15 00:38:51 -04:00
|
|
|
module ActionMailer # :nodoc:
|
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)
|
2012-09-19 19:00:28 -04:00
|
|
|
return unless logger.info?
|
2012-01-05 14:24:48 -05:00
|
|
|
recipients = Array(event.payload[:to]).join(', ')
|
2012-09-19 19:00:28 -04:00
|
|
|
info("\nSent mail to #{recipients} (#{event.duration.round(1)}ms)")
|
2010-06-24 07:23:43 -04:00
|
|
|
debug(event.payload[:mail])
|
|
|
|
end
|
|
|
|
|
2013-05-15 00:19:38 -04:00
|
|
|
# An email was received.
|
2010-06-24 07:23:43 -04:00
|
|
|
def receive(event)
|
2012-09-19 19:00:28 -04:00
|
|
|
return unless logger.info?
|
|
|
|
info("\nReceived mail (#{event.duration.round(1)}ms)")
|
2010-06-24 07:23:43 -04:00
|
|
|
debug(event.payload[:mail])
|
|
|
|
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
|