Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[HttpKernel] Decouple exception logging from rendering #25366

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

Merged
merged 1 commit into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions 5 src/Symfony/Component/HttpKernel/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

4.1.0
-----

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it worth to add this to the upgrade file too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What exactly needs an upgrade step?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking about other listeners that relied on this one being executed before/after themselves. Probably an edge case though that's not needed to be tackled.


4.0.0
-----

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

public function onKernelException(GetResponseForExceptionEvent $event)
public function logKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$request = $event->getRequest();

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

$request = $this->duplicateRequest($exception, $request);
public function onKernelException(GetResponseForExceptionEvent $event)
{
$exception = $event->getException();
$request = $this->duplicateRequest($exception, $event->getRequest());

try {
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
Expand Down Expand Up @@ -72,7 +75,10 @@ public function onKernelException(GetResponseForExceptionEvent $event)
public static function getSubscribedEvents()
{
return array(
KernelEvents::EXCEPTION => array('onKernelException', -128),
KernelEvents::EXCEPTION => array(
array('logKernelException', 2048),
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 => 'onKernelException',
KernelEvents::EXCEPTION => array('onKernelException', 2048),
KernelEvents::TERMINATE => array('onKernelTerminate', -1024),
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ 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 @@ -72,11 +74,13 @@ 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.