我使用的这段代码工作得很好,但对我来说没有意义,因为这段代码意味着只有当达到错误级别时才会触发主处理程序,然后它才会被记录或通过电子邮件发送。事实上,所有消息仍会记录到该文件中。我错过了什么?
monolog: handlers: main: type: fingers_crossed action_level: error excluded_404s: - ^/ handler: grouped grouped: type: group members: [streamed, deduplicated] streamed: type: stream path: "%kernel.logs_dir%/%kernel.environment%.log" level: debug deduplicated: type: deduplication handler: swift swift: type: swift_mailer from_email: %noreply_email% to_email: %webmaster_email% subject: 'Error Notification %%message%%' level: error formatter: monolog.formatter.html content_type: text/html login: type: stream path: "%kernel.logs_dir%/auth.log" level: info channels: security nested: type: stream path: "%kernel.logs_dir%/%kernel.environment%.log" level: debug console: type: console
monolog: handlers: streamed: type: stream path: "%kernel.logs_dir%/%kernel.environment%.log" level: debug emailed: type: fingers_crossed action_level: error excluded_404s: - ^/ handler: swift swift: type: swift_mailer from_email: %noreply_email% to_email: %webmaster_email% subject: 'Error Notification %%message%%' level: error formatter: monolog.formatter.html content_type: text/html login: type: stream path: "%kernel.logs_dir%/auth.log" level: info channels: security console: type: console
所有消息仍会记录到该文件中。我错过了什么?
它起作用的原因是你也有 nested 处理程序 ,使其(从Monogbundle的角度)成为顶级处理程序(意味着它将接收应用程序中生成的所有日志)。此外,它指向与 streamed
nested
streamed
main 处理程序将收集日志,直到出现错误(404s除外),然后将 一切都归结到 grouped 和 deduplicated 处理程序
main
grouped
deduplicated