Skip to content

Navigation Menu

Sign in
Appearance settings

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

Commit a19afcd

Browse filesBrowse files
committed
feature #25366 [HttpKernel] Decouple exception logging from rendering (ro0NL)
This PR was merged into the 4.1-dev branch. Discussion ---------- [HttpKernel] Decouple exception logging from rendering | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #25266 | License | MIT | Doc PR | symfony/symfony-docs#... <!--highly recommended for new features--> Given your controller throws an exception and a custom exception listener sets a response. Before ![image](https://user-images.githubusercontent.com/1047696/33676886-46e90e0a-dab7-11e7-9a3a-24c70b23d4e0.png) After ![image](https://user-images.githubusercontent.com/1047696/33676832-1ac4f0aa-dab7-11e7-9ac4-483fcbdc06ee.png) ;-) edit: raising the priority for the profiler listener fixes the exception panel also. Commits ------- a203d31 [HttpKernel] Decouple exception logging from rendering
2 parents 1cf1ae7 + a203d31 commit a19afcd
Copy full SHA for a19afcd

File tree

4 files changed

+20
-5
lines changed
Filter options

4 files changed

+20
-5
lines changed

‎src/Symfony/Component/HttpKernel/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
4.1.0
5+
-----
6+
7+
* `ExceptionListener` now logs and collects exceptions at priority `2048` (previously logged at `-128` and collected at `0`)
8+
49
4.0.0
510
-----
611

‎src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/ExceptionListener.php
+10-4Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,17 @@ public function __construct($controller, LoggerInterface $logger = null)
3737
$this->logger = $logger;
3838
}
3939

40-
public function onKernelException(GetResponseForExceptionEvent $event)
40+
public function logKernelException(GetResponseForExceptionEvent $event)
4141
{
4242
$exception = $event->getException();
43-
$request = $event->getRequest();
4443

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

47-
$request = $this->duplicateRequest($exception, $request);
47+
public function onKernelException(GetResponseForExceptionEvent $event)
48+
{
49+
$exception = $event->getException();
50+
$request = $this->duplicateRequest($exception, $event->getRequest());
4851

4952
try {
5053
$response = $event->getKernel()->handle($request, HttpKernelInterface::SUB_REQUEST, false);
@@ -72,7 +75,10 @@ public function onKernelException(GetResponseForExceptionEvent $event)
7275
public static function getSubscribedEvents()
7376
{
7477
return array(
75-
KernelEvents::EXCEPTION => array('onKernelException', -128),
78+
KernelEvents::EXCEPTION => array(
79+
array('logKernelException', 2048),
80+
array('onKernelException', -128),
81+
),
7682
);
7783
}
7884

‎src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/EventListener/ProfilerListener.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public static function getSubscribedEvents()
121121
{
122122
return array(
123123
KernelEvents::RESPONSE => array('onKernelResponse', -100),
124-
KernelEvents::EXCEPTION => 'onKernelException',
124+
KernelEvents::EXCEPTION => array('onKernelException', 2048),
125125
KernelEvents::TERMINATE => array('onKernelTerminate', -1024),
126126
);
127127
}

‎src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php
+4Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,13 @@ public function testHandleWithoutLogger($event, $event2)
5151
$this->iniSet('error_log', file_exists('/dev/null') ? '/dev/null' : 'nul');
5252

5353
$l = new ExceptionListener('foo');
54+
$l->logKernelException($event);
5455
$l->onKernelException($event);
5556

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

5859
try {
60+
$l->logKernelException($event2);
5961
$l->onKernelException($event2);
6062
$this->fail('RuntimeException expected');
6163
} catch (\RuntimeException $e) {
@@ -72,11 +74,13 @@ public function testHandleWithLogger($event, $event2)
7274
$logger = new TestLogger();
7375

7476
$l = new ExceptionListener('foo', $logger);
77+
$l->logKernelException($event);
7578
$l->onKernelException($event);
7679

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

7982
try {
83+
$l->logKernelException($event2);
8084
$l->onKernelException($event2);
8185
$this->fail('RuntimeException expected');
8286
} catch (\RuntimeException $e) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.