Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 945c7c5

Browse files
committed
minor #39920 [Console] Fix console logger according to PSR-3 (alex-dev)
This PR was merged into the 4.4 branch. Discussion ---------- [Console] Fix console logger according to PSR-3 | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #39050, #29138 | License | MIT `Symfony\Component\HttpKernel\EventListener\ErrorListener` logs non-HTTP exceptions at `LogLevel::CRITICAL`. `Symfony\Component\Messenger\Worker` logs unrecoverable exceptions at `LogLevel::CRITICAL`. `Symfony\Component\Console\EventListener\ErrorListener` logs exceptions at `LogLevel::ERROR`. As per PSR-3, unexpected and unrecoverable exceptions should be logged at `LogLevel::CRITICAL`. Commits ------- 69fcd07 Fix console logger according to PSR-3
2 parents be788ee + 69fcd07 commit 945c7c5

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ public function onConsoleError(ConsoleErrorEvent $event)
4040
$error = $event->getError();
4141

4242
if (!$inputString = $this->getInputString($event)) {
43-
$this->logger->error('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]);
43+
$this->logger->critical('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => $error->getMessage()]);
4444

4545
return;
4646
}
4747

48-
$this->logger->error('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]);
48+
$this->logger->critical('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => $inputString, 'message' => $error->getMessage()]);
4949
}
5050

5151
public function onConsoleTerminate(ConsoleTerminateEvent $event)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function testOnConsoleError()
3333
$logger = $this->createMock(LoggerInterface::class);
3434
$logger
3535
->expects($this->once())
36-
->method('error')
36+
->method('critical')
3737
->with('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => 'test:run --foo=baz buzz', 'message' => 'An error occurred'])
3838
;
3939

@@ -48,7 +48,7 @@ public function testOnConsoleErrorWithNoCommandAndNoInputString()
4848
$logger = $this->createMock(LoggerInterface::class);
4949
$logger
5050
->expects($this->once())
51-
->method('error')
51+
->method('critical')
5252
->with('An error occurred while using the console. Message: "{message}"', ['exception' => $error, 'message' => 'An error occurred'])
5353
;
5454

0 commit comments

Comments
 (0)