【问题标题】:symfony2 exceptions without logging没有记录的 symfony2 异常
【发布时间】:2014-06-01 14:37:48
【问题描述】:

我的应用程序中有几个地方作为业务逻辑的一部分抛出异常,但我不需要 Symfony2 来生成和记录异常。

例如,当用户尝试执行他暂时无法执行的操作时,我会调用 $this->createAccessDeniedException() 并显示一条不错的错误消息。这不是应用程序故障,我不需要记录它。大多数情况下,它是给用户的一条消息,说“稍后再试,或者在你先完成其他步骤之后再试”。

我可以教它不记录某些案例还是我使用异常不当,如果是,我应该怎么做?

更新:我的配置:

monolog:
    handlers:
        main:
            type:         fingers_crossed
            action_level: error
            handler:      grouped
        grouped:
            type:       group
            members:    [streamed, buffered]
        streamed:
            type:       stream
            path:       %kernel.logs_dir%/%kernel.environment%.log
            level:      debug
        buffered:
            type:       buffer
            handler:    swift
        swift:
            type:       swift_mailer
            from_email: xxx@xxx.xxx
            to_email:   xxx@xxx.xxx
            subject:    "Error"
            level:      info

【问题讨论】:

    标签: symfony monolog


    【解决方案1】:

    正如您在ExceptionListener 中所见,AccessDeniedException 不应被记录为正常异常,而应作为 DEBUG 级别的特殊消息。

    如果您在生产日志文件中看到这些消息,则应检查为 Monolog 配置的最低级别。我建议将其设置为 NOTICE。

    【讨论】:

    • 见上文 - 我以为我已经配置了它,以便它只在错误时发送邮件。
    猜你喜欢
    • 2012-09-11
    • 2011-06-04
    • 1970-01-01
    • 2012-07-26
    • 1970-01-01
    • 2011-03-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多