2
我已經建立了獨白我們的Symfony2項目發生時,他們通過電子郵件發送了嚴重的錯誤給我們。的Symfony2 +獨白:不同的行動不同的誤差水平
不過,我也想記錄非關鍵性錯誤還,並通過電子郵件發送這些錯誤到不同的收件人。我很努力地在文檔中看到它,但它看起來應該是可能的。我已經設置瞭如下配置:
parameters:
error_mail_sender: [email protected]
error_mail_recipients: [[email protected]]
critical_error_mail_recipients: [[email protected], [email protected]]
monolog:
handlers:
main_critical:
type: fingers_crossed
action_level: critical
handler: grouped_critical
bubble: false
main_error:
type: fingers_crossed
action_level: error
handler: grouped_error
grouped_critical:
type: group
members: [streamed, buffered_critical]
grouped_error:
type: group
members: [streamed, buffered_error]
streamed:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
buffered_critical:
type: buffer
handler: swift_critical
buffered_error:
type: buffer
handler: swift_error
swift_critical:
type: swift_mailer
from_email: %error_mail_sender%
to_email: %error_mail_recipients%
subject: Critical error occurred!
level: debug
swift_error:
type: swift_mailer
from_email: %error_mail_sender%
to_email: %critical_error_mail_recipients%
subject: Non-critical error occurred
level: debug
使用此設置,我們會收到嚴重錯誤,但不會收到非嚴重錯誤。
這一套了鬆散基礎上的(接受的)這個問題的答案:How to include the severity of a log in the e-mail subject?。 (我將有上投了答案了它的工作對我!)
任何人都可以發現有什麼不對呢?
謝謝!
對於其他人來說,這種配置將導致2封電子郵件被髮送出現嚴重錯誤,每個處理程序一個。目前無法避免這種情況,正如Seldaek在這裏向我解釋的那樣:https://github.com/Seldaek/monolog/issues/131#issuecomment-10884955 – lopsided
我更新了代碼片段 – Seldaek