0

I'm working on an API with Symfony and FosRestBundle.

In my ApiController, I want to log all exception in a specific file: api.log

Here an example of my code:

   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;
    }

Where i need to catch and log the exeption ? In if(!is_object($user)){ or when i retrieve $user ? And How can i save and log the exeption in my file api.log ?

Thanks !

1 Answer 1

1

In my opinion should add a kernel.exception event listener, which writes the exception in the api.log file

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.