用于电子邮件和文件记录的 Symfony2 Monolog 设置 [英] Symfony2 Monolog Settings for email and file logging

查看:26
本文介绍了用于电子邮件和文件记录的 Symfony2 Monolog 设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想设置 Symfony2 向我发送 critical 错误的电子邮件,但只记录 error 级别的错误.以下设置会这样做吗?

I want to setup Symfony2 to send me an email for critical errors, but just log error level errors. Will the following settings do that?

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,这是我仍然想要日志(但没有电子邮件)的情况.我很确定我的配置会起作用,但我对 monolog 设置了解得不够多.请告诉我这是否正确或是否有更好的方法.

I saw: http://symfony.com/doc/current/cookbook/logging/monolog_email.html But it doesn't handle error at all, which is a case where I still want logs (but no email). I was pretty sure my config would work, but I don't know enough about the monolog settings. Please let me know if this is correct or if there is a better way.

推荐答案

以下是我的生产 Monolog 配置.这是确认工作发送严重错误,同时将错误"级别及以上记录到文件中.我还拆分了不同的频道以分离文件.其他渠道似乎产生的错误远远少于请求",因此对我来说在生产中将它们分开是有意义的.意识到这不是你的问题,但希望它可以帮助其他人;这可以缩减以满足大多数要求.

The following is my production monolog config. This is confirmed working sending critical errors, whilst logging 'error' level and above to file. I've also split out the different channels to separate files. The other channels seem to produce errors far less than 'request', so it makes sense to split them out in production for me. Realise that's not your question, but hope it helps someone else; this can pared back to fit most requirements.

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

这篇关于用于电子邮件和文件记录的 Symfony2 Monolog 设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆