You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为什么Symfony的Monolog发送错误通知时会额外推送邮件?

问题原因

你收到额外debug邮件是因为Monolog的fingers_crossed处理器触发critical级别报错后,会将缓冲区中所有满足级别要求的日志全部打包发送,你当前配置的邮件处理器级别为debug,且未过滤mailer通道日志,发送错误邮件时SMTP连接启停的debug日志刚好被缓冲区捕获,所以会额外收到这类邮件。

解决方案

有两种常用的配置修改方案,选任意一种即可:

方案1:排除mailer通道的日志不发送邮件

在symfony_mailer处理器配置中增加channels参数,排除mailer通道的日志:

monolog:
    handlers:
        # 其他原有配置保持不变
        symfony_mailer:
            type:         symfony_mailer
            from_email:   'infoexample@gmail.com'
            to_email:     'example@gmail.com'
            subject:      'An Error Occurred! %%message%%'
            level:        debug
            formatter:    monolog.formatter.html
            content_type: text/html
            # 新增以下行,排除mailer通道的日志
            channels: ["!mailer"]

如果需要排除多个通道,可以按格式添加,比如["!mailer", "!doctrine"]。

方案2:提高邮件发送的最低日志级别

将symfony_mailer的level参数从debug调整为error或更高(比如critical),仅高于等于该级别的日志会被发送,自然过滤掉debug级别的mailer日志:

monolog:
    handlers:
        # 其他原有配置保持不变
        symfony_mailer:
            type:         symfony_mailer
            from_email:   'infoexample@gmail.com'
            to_email:     'example@gmail.com'
            subject:      'An Error Occurred! %%message%%'
            # 将debug改为error或更高
            level:        error
            formatter:    monolog.formatter.html
            content_type: text/html

如果需要保留所有非mailer通道的debug日志用于问题排查,优先选方案1即可。

内容的提问来源于stack exchange,提问作者Daymer Rodriguez Fillad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.06 09:54:03