代码之家  ›  专栏  ›  技术社区  ›  ZeSoft

使用monolog Symfony记录所有消息和仅电子邮件错误

  •  0
  • ZeSoft  · 技术社区  · 7 年前

    我使用的这段代码工作得很好,但对我来说没有意义,因为这段代码意味着只有当达到错误级别时才会触发主处理程序,然后它才会被记录或通过电子邮件发送。事实上,所有消息仍会记录到该文件中。我错过了什么?

    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
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Xymanek Tomas Jansson    7 年前

    所有消息仍会记录到该文件中。我错过了什么?

    它起作用的原因是你也有 nested 处理程序 ,使其(从Monogbundle的角度)成为顶级处理程序(意味着它将接收应用程序中生成的所有日志)。此外,它指向与 streamed

    main 处理程序将收集日志,直到出现错误(404s除外),然后将 一切都归结到 grouped deduplicated 处理程序