当我发送带有附件的电子邮件时,数据将以十六进制记录,并填满我的整个日志。有没有办法禁用附件的日志记录?我知道我可以用config.action_mailer.logger = nil
禁用邮件日志。
发布于 2012-02-08 09:42:15
在Application.rb
中,您可以尝试过滤附件参数。我相信这应该可以解决这个问题,但我还没有亲自测试过
config.filter_parameters += [:attachment]
发布于 2018-11-07 09:18:27
如果您仍然希望将日志级别设置为debug,则可以通过覆盖ActionMailer的LogSubscriber类来从日志输出中删除附件。查看actionmailer gem中的类,并进行相应的调整。对于我的Rails 4.2.10安装,相关文件是:gems/actionmailer-4.2.10/lib/action_mailer/log_subscriber.rb
我的模块是:
module ActionMailer
class LogSubscriber < ActiveSupport::LogSubscriber
def deliver(event)
info do
recipients = Array(event.payload[:to]).join(', ')
"\nSent mail to #{recipients}, Subject: #{event.payload[:subject]}, on #{event.payload[:date]} (#{event.duration.round(1)}ms)"
end
debug { remove_attachments(event.payload[:mail]) }
end
def remove_attachments(message)
new_message = ''
skip = false
message.each_line do |line|
new_message << line unless skip
skip = true if line =~ /Content-Disposition: attachment;/
skip = false if skip && line =~ /----==_mimepart/
end
new_message
end
end
end
将此文件保存到您的应用程序/文件夹下的任何位置的.rb文件,它将被包括在内。
https://stackoverflow.com/questions/9073814
复制相似问题