8000 [HttpKernel] Strip exception file paths from log messages · symfony/symfony@272c13e · GitHub
[go: up one dir, main page]

Skip to content

Commit 272c13e

Browse files
committed
[HttpKernel] Strip exception file paths from log messages
1 parent 489c887 commit 272c13e

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/Symfony/Component/HttpKernel/EventListener/ErrorListener.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function logKernelException(ExceptionEvent $event)
9090

9191
$e = FlattenException::createFromThrowable($throwable);
9292

93-
$this->logException($throwable, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), $e->getFile(), $e->getLine()), $logLevel);
93+
$this->logException($throwable, sprintf('Uncaught PHP Exception %s: "%s" at %s line %s', $e->getClass(), $e->getMessage(), basename($e->getFile()), $e->getLine()), $logLevel);
9494
}
9595

9696
/**
@@ -118,7 +118,7 @@ public function onKernelException(ExceptionEvent $event)
118118
} catch (\Exception $e) {
119119
$f = FlattenException::createFromThrowable($e);
120120

121-
$this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', $f->getClass(), $f->getMessage(), $e->getFile(), $e->getLine()));
121+
$this->logException($e, sprintf('Exception thrown when handling an exception (%s: %s at %s line %s)', $f->getClass(), $f->getMessage(), basename($e->getFile()), $e->getLine()));
122122

123123
$prev = $e;
124124
do {

src/Symfony/Component/HttpKernel/Tests/EventListener/ErrorListenerTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,11 @@ public function testHandleWithLogger($event, $event2)
9696
}
9797

9898
$this->assertEquals(3, $logger->countErrors());
99-
$this->assertCount(3, $logger->getLogs('critical'));
99+
$logs = $logger->getLogs('critical');
100+
$this->assertCount(3, $logs);
101+
$this->assertStringStartsWith('Uncaught PHP Exception Exception: "foo" at ErrorListenerTest.php line', $logs[0]);
102+
$this->assertStringStartsWith('Uncaught PHP Exception Exception: "foo" at ErrorListenerTest.php line', $logs[1]);
103+
$this->assertStringStartsWith('Exception thrown when handling an exception (RuntimeException: bar at ErrorListenerTest.php line', $logs[2]);
100104
}
101105

102106
public function testHandleWithLoggerAndCustomConfiguration()

0 commit comments

Comments
 (0)
0