Ros*_*oss 7 ruby-on-rails actionmailer ruby-on-rails-3
在Rails中通过Actionmailer发送电子邮件时,它会记录如下内容:
Sent mail to example@example.com (72ms)
Rendered mailer/_header.html.erb (0.0ms)
...
Run Code Online (Sandbox Code Playgroud)
我想过滤日志ala参数过滤的电子邮件
Sent mail to [FILTERED] (72ms)
Rendered mailer/_header.html.erb (0.0ms)
...
Run Code Online (Sandbox Code Playgroud)
有干净的方法吗?或者,不记录整个第一行就没问题.
小智 0
您可以为当前的操作邮件程序进行猴子修补:
在“lib”目录中创建一个包含如下内容的文件(复制并粘贴步骤 2 中的代码,并将“recipients”更改为“[FILTERED]”:
module ActionMailer
class LogSubscriber < ActiveSupport::LogSubscriber
def deliver(event)
return unless logger.info?
#recipients = Array(event.payload[:to]).join(', ')
info("\nSent mail to [FILTERED] (#{event.duration.round(1)}ms)")
debug(event.payload[:mail])
end
end
end
Run Code Online (Sandbox Code Playgroud)对于我的 action_mailer 版本,代码如下:
def deliver!(mail = @mail)
raise "no mail object available for delivery!" unless mail
unless logger.nil?
logger.info "Sent mail to [FILTERED]"
# instead of original logger.info "Sent mail to #{Array(recipients).join(', ')}"
logger.debug "\n#{mail.encoded}"
end
begin
__send__("perform_delivery_#{delivery_method}", mail) if perform_deliveries
rescue Exception => e # Net::SMTP errors or sendmail pipe errors
raise e if raise_delivery_errors
end
return mail
end
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
771 次 |
| 最近记录: |