Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8190577
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T03:42:12+00:00 2026-06-07T03:42:12+00:00

I want to be alerted when bad things happen in my Symfony2 app. Right

  • 0

I want to be alerted when bad things happen in my Symfony2 app. Right now I just look for ERROR in the logs. Unfortunately, “HTTP 404 – file not found” (NotFoundHttpException) gets logged as an error, as does “HTTP 403 – forbidden” (AccessDeniedHttpException).

This doesn’t warrant an error; at the most these should be warnings. How can I make these log at a less severe level?

Example error:

[2012-07-02 16:58:21] request.ERROR: Symfony\Component\HttpKernel\Exception\NotFoundHttpException: No route found for "GET /foo" (uncaught exception) at /home/user/Symfony2_v2.0.12/vendor/symfony/src/Symfony/Bundle/FrameworkBundle/EventListener/RouterListener.php line 83 [] []
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T03:42:13+00:00Added an answer on June 7, 2026 at 3:42 am

    I found something that works. The Symfony2 internals doc on the kernel.exeption event mention that a response can be set on the event, and the GetResponseForExceptionEvent docs say

    The propagation of this event is stopped as soon as a
    response is set.

    I cobbled together a listener that appears to do just what I want:

    <?php
    
    namespace Acme\DemoBundle\Listener;
    
    use Symfony\Component\EventDispatcher\EventDispatcher;
    use Symfony\Component\HttpKernel\Log\LoggerInterface;
    use Symfony\Component\EventDispatcher\Event;
    use Symfony\Component\HttpKernel\KernelEvents;
    use Symfony\Component\HttpFoundation\Response;
    use Symfony\Component\HttpKernel\Event\GetResponseForExceptionEvent;
    
    class ExceptionLoggingListener {
      private $logger;
    
      public function __construct(LoggerInterface $logger) {
        $this->logger = $logger;
      }
    
      public function onKernelException(GetResponseForExceptionEvent $event) {
        if(!$event) {
          $this->logger->err("Unknown kernel.exception in ".__CLASS__);
          return;
        }
        $notFoundException = '\Symfony\Component\HttpKernel\Exception\NotFoundHttpException';
    
        $e = $event->getException();
        $type = get_class($e);
        if ($e instanceof $notFoundException) {
          $this->logger->info($e->getMessage());
          $response = new Response(Response::$statusTexts[404], 404);
          $event->setResponse($response);
          return;
        }
    
        $accessDeniedException = '\Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException';
        if ($e instanceof $accessDeniedException) {
          $this->logger->info($e->getMessage());
          $response = new Response(Response::$statusTexts[403], 403);
          $event->setResponse($response);
          return;
        }
        $this->logger->err("kernel.exception of type $type. Message: '".$e->getMessage()."'\nFile: ".$e->getFile().", line ".$e->getLine()."\nTrace: ".$e->getTraceAsString());
      }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made up an editable PDF for students to request transcripts. Now, I want
I want to be alerted, if a headset is plugged in. But the Intent
I want to completely remove error list from visual studio 2008, not disable it
I want to get alerted whenever I press a key. I've tried: $('body').live('keyup', function()
I have a pretty standard attendance database design, but I want to be alerted
I want to make an auto synchronize in my application that will happen every
My company has 6 apps in the App Store. I want to know if
i have a client who says they want an messaging based app which has
want to open pdf file when a user clicks on hyperlink shown in gridview
Want to run javascript function from parent window in child window Example I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.