8000 [HttpKernel][DX] Allow the log level of http exceptions to be overridden by mtibben · Pull Request #25533 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[HttpKernel][DX] Allow the log level of http exceptions to be overridden #25533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "[HttpKernel] Decouple exception logging from rendering"
This reverts commit a203d31.
  • Loading branch information
mtibben committed Jan 19, 2018
commit 9236f62a0c950672be796174a05e9c2ae3c7f53a
5 changes: 0 additions & 5 deletions src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
CHANGELOG
=========

4.1.0
-----

* `ExceptionListener` now logs and collects exceptions at priority `2048` (previously logged at `-128` and collected at `0`)

4.0.0
-----

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,19 +43,15 @@ public function __construct($controller, LoggerInterface $logger = null)
$this->logger = $logger;
}

public function logKernelException(GetResponseForExceptionEvent $event)
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$request = $event->getRequest();
$eventDispatcher = func_num_args() > 2 ? func_get_arg(2) : null;

$this->logException($exception, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine()));
}

public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$request = $this->duplicateRequest($exception, $event->getRequest());
$eventDispatcher = func_num_args() > 2 ? func_get_arg(2) : null;
$request = $this->duplicateRequest($exception, $request);

try {
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
Expand Down Expand Up @@ -91,10 +87,7 @@ public function onKernelException(GetResponseForExceptionEvent $event)
public static function getSubscribedEvents()
{
return array(
KernelEvents::EXCEPTION => array(
array('logKernelException', 2048),
array('onKernelException', -128),
),
KernelEvents::EXCEPTION => array('onKernelException', -128),
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public static function getSubscribedEvents()
{
return array(
KernelEvents::RESPONSE => array('onKernelResponse', -100),
KernelEvents::EXCEPTION => array('onKernelException', 2048),
KernelEvents::EXCEPTION => 'onKernelException',
KernelEvents::TERMINATE => array('onKernelTerminate', -1024),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,11 @@ public function testHandleWithoutLogger($event, $event2)
$this->iniSet('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');

$l = new ExceptionListener('foo');
$l->logKernelException($event);
$l->onKernelException($event);

$this->assertEquals(new Response('foo'), $event->getResponse());

try {
$l->logKernelException($event2);
$l->onKernelException($event2);
$this->fail('RuntimeException expected');
} catch (\RuntimeException $e) {
Expand All @@ -78,13 +76,11 @@ public function testHandleWithLogger($event, $event2)
$logger = new TestLogger();

$l = new ExceptionListener('foo', $logger);
$l->logKernelException($event);
$l->onKernelException($event);

$this->assertEquals(new Response('foo'), $event->getResponse());

try {
$l->logKernelException($event2);
$l->onKernelException($event2);
$this->fail('RuntimeException expected');
} catch (\RuntimeException $e) {
Expand Down Expand Up @@ -164,7 +160,6 @@ public function testHttp4xxLogLevel()
$exception = new \Exception('foo');
$event = new GetResponseForExceptionEvent(new TestKernelThatThrowsHttp4xxException(), Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $exception);
try {
$l->logKernelException($event);
$l->onKernelException($event);
$this->fail('NotFoundHttpException expected');
} catch (NotFoundHttpException $e) {
Expand All @@ -183,7 +178,6 @@ public function testHttpLogLevelOverride()
$exception = new \Exception('foo');
$event = new GetResponseForExceptionEvent(new TestKernelThatThrowsHttp4xxException(), Request::create('/'), HttpKernelInterface::MASTER_REQUEST, $exception);
try {
$l->logKernelException($event);
$l->onKernelException($event);
$this->fail('NotFoundHttpException expected');
} catch (NotFoundHttpException $e) {
Expand Down
0