diff options
Diffstat (limited to 'actionmailer/lib/action_mailer/log_subscriber.rb')
-rw-r--r-- | actionmailer/lib/action_mailer/log_subscriber.rb | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/actionmailer/lib/action_mailer/log_subscriber.rb b/actionmailer/lib/action_mailer/log_subscriber.rb index 3fe64759ac..5b57c75ec3 100644 --- a/actionmailer/lib/action_mailer/log_subscriber.rb +++ b/actionmailer/lib/action_mailer/log_subscriber.rb @@ -1,18 +1,35 @@ +require 'active_support/log_subscriber' + module ActionMailer + # Implements the ActiveSupport::LogSubscriber for logging notifications when + # email is delivered and received. class LogSubscriber < ActiveSupport::LogSubscriber + # An email was delivered. def deliver(event) - return unless logger.info? - recipients = Array(event.payload[:to]).join(', ') - info("\nSent mail to #{recipients} (#{event.duration.round(1)}ms)") - debug(event.payload[:mail]) + info do + recipients = Array(event.payload[:to]).join(', ') + "\nSent mail to #{recipients} (#{event.duration.round(1)}ms)" + end + + debug { event.payload[:mail] } end + # An email was received. def receive(event) - return unless logger.info? - info("\nReceived mail (#{event.duration.round(1)}ms)") - debug(event.payload[:mail]) + info { "\nReceived mail (#{event.duration.round(1)}ms)" } + debug { event.payload[:mail] } + end + + # An email was generated. + def process(event) + debug do + mailer = event.payload[:mailer] + action = event.payload[:action] + "\n#{mailer}##{action}: processed outbound mail in #{event.duration.round(1)}ms" + end end + # Use the logger configured for ActionMailer::Base def logger ActionMailer::Base.logger end |