【问题标题】:Symfony2, log exception in specific fileSymfony2,在特定文件中记录异常
【发布时间】:2014-07-03 12:44:39
【问题描述】:

我正在使用 Symfony 和 FosRestBundle 开发 API。

在我的 ApiController 中,我想在特定文件中记录所有异常:api.log

这是我的代码示例:

   public function getUserAction($param){
        if(is_int($param)){
            $user = $this->getDoctrine()->getRepository('ProjectBundle:Account')->findOneById($param);
        }
        else{
            $user = $this->getDoctrine()->getRepository('ProjectBundle:Account')->findOneByUsername($param);
        }

        if(!is_object($user)){
            return "User Not Found";
        }

        return $user;
    }

我需要在哪里捕获和记录异常?在if(!is_object($user)){ 或当我检索$user 时?以及如何在我的文件 api.log 中保存和记录异常?

谢谢!

【问题讨论】:

    标签: php symfony exception


    【解决方案1】:

    我认为应该添加一个 kernel.exception 事件监听器,它将异常写入 api.log 文件中

    http://symfony.com/doc/current/cookbook/service_container/event_listener.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-24
      • 2012-09-11
      • 2020-02-27
      • 1970-01-01
      • 1970-01-01
      • 2011-09-02
      • 1970-01-01
      相关资源
      最近更新 更多