2017-08-28 41 views
1

我想將所有消息記錄到日誌文件,但只有在排除404 我用這個代碼的正常工作錯誤的情況下發送電子郵件的錯誤,但它並沒有任何意義,我,因爲這個代碼意味着只有達到錯誤級別時纔會觸發主處理程序,那麼它將被記錄或通過電子郵件發送。實際上所有消息仍然記錄到文件中。我在這裏錯過了什麼?日誌中的所有郵件和電子郵件只能用獨白的Symfony

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 

回答

2

所有消息仍記錄到文件中。我在這裏錯過了什麼?

它的工作原理的原因是,你也有nested處理實際上沒有嵌套,使得它(從視圖MonologBu​​ndle點)的頂級處理器(這意味着它會收到生成的所有日誌在你的應用程序中)。此外,它指向同一文件從而streamed處理程序使得不可能區分哪些處理程序是響應於特定的記錄的消息。

這個代碼意味着主處理器將不會被觸發只有在達到誤差的水平,那麼它會被記錄或電子郵件

是的,直到它得到一個錯誤main處理程序會收集日誌(除了404),然後它會沖洗都記錄下來,以grouped處理這反過來又管一切streameddeduplicated處理

+0

感謝Xymanek現在我明白了,所以要記錄所有日誌和電子郵件僅錯誤不包括404。我將編輯我的問題以包含我的最終代碼,請查看它是否正確。 – ZeSoft

+0

@ZeSoft你仍然需要包裝''一個一個fingers_crossed'裏面deduplicated'處理。 'excluded_404s'選項僅適用於手指交叉處理類型 – Xymanek

+0

謝謝@Xymanek的回答,所以我編輯我上面的代碼和我刪除了重複數據刪除的處理程序,並直接分配迅速處理程序,以電子郵件的處理程序,它的好處是現在?類型重複數據刪除是什麼意思? – ZeSoft

相關問題