2

我正在将 Monolog 与 Symfony2 一起使用,并配置了一个日志记录环境,其中所有内容都记录到文件中,并且超过某个阈值会通过电子邮件发送给我。我的配置如下。

但是,我无法调整电子邮件主题,使其根据日志的实际级别进行更改。响应时间的差异,例如警告和关键,可能会有所不同。有没有办法做到这一点?

monolog:
    handlers:
        main:
            type:  stream
            path:  %kernel.logs_dir%/%kernel.environment%.log
            level: debug
        mail:
            type:         fingers_crossed
            action_level: %logger_level%
            handler:      buffered
        buffered:
            type:    buffer
            handler: swift
        swift:
            type:       swift_mailer
            from_email: %logger_from_email%
            to_email:   %logger_to_email%
            subject:    Log  # I want the subject to include the log level somehow
            level:      debug
4

2 回答 2

0

您可以定义两个不同的处理程序(或处理程序链):一个由低级问题激活,另一个由更严重的问题激活。他们发送的电子邮件有不同的主题。就像是:

monolog:
    handlers:
        mail_critical:
            type:         fingers_crossed
            action_level: critical
            handler:      buffered_critical
            bubble: false
        buffered_critical:
            type:    buffer
            handler: swift_critical
        swift_critical:
            type:       swift_mailer
            from_email: %logger_from_email%
            to_email:   %logger_to_email%
            subject:    CALL 911, YOUR SITE IS BURNING
            level:      critical
        mail_debug:
            type:         fingers_crossed
            action_level: debug
            handler:      buffered_debug
        buffered_debug:
            type:    buffer
            handler: swift_debug
        swift_debug:
            type:       swift_mailer
            from_email: %logger_from_email%
            to_email:   %logger_to_email%
            subject:    Just a normal error
            level:      debug
于 2012-09-18T20:25:15.763 回答
0

您可以在主题中包含%%level%%。它将添加int

或者您可以添加%%level_name%%它将添加腿部级别名称的字符串

        swift:
        type:       swift_mailer
        from_email: '%env(ADMIN_EMAIL)%'
        to_email:   '%env(ADMIN_EMAIL)%'
        subject:    '[%kernel.environment%] [LEVEL CODE:%%level%%][LEVEL NAME:%%level_name%%] Some subject text! %%message%%'
        level:      error
        formatter:  monolog.formatter.html
        content_type: text/html

更多可以在这里找到https://github.com/Seldaek/monolog/blob/master/doc/message-structure.md

于 2018-08-09T05:15:16.517 回答