6

我想设置 Symfony2 向我发送一封critical错误电子邮件,但只是日志error级别的错误。以下设置会这样做吗?

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      grouped
        grouped:
            type: group
            members: [filelog, mail]
        # log all errors to file
        filelog:
            type:         fingers_crossed
            action_level: error
            handler:      nested_stream
        nested_stream:
            type:  stream
            path:  "%kernel.logs_dir%/%kernel.environment%.log"
            level: debug
        # send me an email when we have a critical error
        mail:
            type:         fingers_crossed
            action_level: critical
            handler:      buffered
        buffered:
            type:    buffer
            handler: swift
        swift:
            type:       swift_mailer
            from_email: %mailer_sender%
            to_email:   %error_email%
            subject:    "[FeedStream Error]"
            level:      debug

我看到了:http ://symfony.com/doc/current/cookbook/logging/monolog_email.html但它根本无法处理error,这是我仍然想要日志(但没有电子邮件)的情况。我很确定我的配置会起作用,但我对独白设置知之甚少。请让我知道这是否正确或是否有更好的方法。

4

1 回答 1

7

以下是我的生产独白配置。这已确认可以发送严重错误,同时将“错误”级别及更高级别记录到文件中。我还拆分了不同的通道来分隔文件。其他渠道产生的错误似乎远少于“请求”,因此对我来说将它们分开生产是有意义的。意识到这不是您的问题,但希望它对其他人有所帮助;这可以缩减以适应大多数要求。

monolog:
  handlers:
    main:
        level: error
        type: stream
        path: "%kernel.logs_dir%/%kernel.environment%_remaining.log"
        channels: ["!doctrine", "!request", "!security"]
    request:
        type: fingers_crossed
        handler: requests
        excluded_404s:
            - ^/phpmyadmin
    requests:
        type:    group
        members: [request_critical, request_error]
    request_critical:
        level: critical
        type: stream
        path: "%kernel.logs_dir%/%kernel.environment%_request_critical.log"
        channels: [request]
    request_error:
        level: error
        type: stream
        path: "%kernel.logs_dir%/%kernel.environment%_request.log"
        channels: [request]
    doctrine:
        level: error
        type: stream
        path: "%kernel.logs_dir%/%kernel.environment%_doctrine.log"
        channels: [doctrine]
    security:
        level: error
        type: stream
        path: "%kernel.logs_dir%/%kernel.environment%_security.log"
        channels: [security]
    mail:
        type: fingers_crossed
        action_level: critical
        handler: buffered
    buffered:
        type: buffer
        handler: swift
    swift:
        type: swift_mailer
        from_email: aj.cerqueti@example.com
        to_email:   aj.cerqueti@example.com
        subject:    A critical error occurred
于 2014-03-06T15:17:41.120 回答