【问题标题】:Configuring monolog in Symfony2在 Symfony2 中配置独白
【发布时间】:2016-02-10 01:34:09
【问题描述】:

我正在尝试优化我的项目日志(因为我的日志现在有 3Gb),以便当出现问题时服务器会向我发送一封包含错误详细信息的电子邮件。

我希望仅在日志中出现重大错误,例如 500 错误,即影响项目正常运行的错误。

我在官方 Symfony2 上查看了独白包的文档,但我一点都不清楚。

(http://symfony.com/doc/current/reference/configuration/monolog.html)

谁能告诉我如何获得这个?

【问题讨论】:

  • 我的回答没有帮助?

标签: symfony monolog


【解决方案1】:

我们定义了

monolog:
    handlers:
        main:
            action_level: error

在我们的生产环境中。 当然,你必须检查你需要适应哪个处理程序(在我们的例子中:'main'),但是通过将 action_level 更改为'error',你可以摆脱日志中的所有调试/信息语句,只有级别'error'是显示。

请检查您的 Swift 部分: 你有 level: 'debug' 这显然不符合你的要求。您应该改用“错误”或“关键”。参见http://symfony.com/doc/current/cookbook/logging/monolog_email.html

一般来说,了解什么样的日志产生了过多的信息以及什么样的信息会很有帮助? (例如,我们将 Doctrine 放到不同的独白频道以在我们的主日志中摆脱它)。

【讨论】:

  • 使用该配置,我的 prod.log 仍在写入所有日志:(
  • 那么你能分享一下你到目前为止的完整独白配置吗?
  • 是的,它现在可以工作了,我做了一些更改,现在我得到了我想要的 :) 非常感谢!
【解决方案2】:

这是我的独白配置。

monolog:
    handlers:
        main:
            action_level: error
        console:
            type:   console
            bubble: false
        mail:
            type: fingers_crossed
            action_level: critical
            handler: buffered
        buffered:
            type: buffer
            handler: swift
        swift:
            type: swift_mailer
            from_email: his@email.com
            to_email: my@email.com
            subject: Critical error spotted
            level: debug

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-07-19
    • 2018-11-15
    • 1970-01-01
    • 1970-01-01
    • 2015-04-15
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多