Skip to content

Instantly share code, notes, and snippets.

@merk
Created September 13, 2013 03:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save merk/6546649 to your computer and use it in GitHub Desktop.
Save merk/6546649 to your computer and use it in GitHub Desktop.
Disable 404 errors
<?php
/**
* This file is part of IBMS
*
* (c) Infinite Networks Pty Ltd <http://www.infinite.net.au>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Ibms\Helper;
use Symfony\Component\HttpKernel\EventListener\ExceptionListener;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class TwigExceptionListener extends ExceptionListener
{
/**
* Logs an exception.
*
* @param \Exception $exception The original \Exception instance
* @param string $message The error message to log
* @param Boolean $original False when the handling of the exception thrown another exception
*/
protected function logException(\Exception $exception, $message, $original = true)
{
$isCritical = !$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500;
if (null !== $this->logger) {
if ($isCritical) {
$this->logger->critical($message);
} else {
if ($exception instanceof NotFoundHttpException) {
$this->logger->info($message);
} else {
$this->logger->error($message);
}
}
} elseif (!$original || $isCritical) {
error_log($message);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment