Skip to content

Commit

Permalink
minor #39920 [Console] Fix console logger according to PSR-3 (alex-dev)
Browse files Browse the repository at this point in the history
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
-------

69fcd075eb Fix console logger according to PSR-3
  • Loading branch information
jderusse committed Jan 28, 2021
2 parents a5e89d5 + 86b9e48 commit 1a9570e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions EventListener/ErrorListener.php
Expand Up @@ -40,12 +40,12 @@ public function onConsoleError(ConsoleErrorEvent $event)
$error = $event->getError();

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

return;
}

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

public function onConsoleTerminate(ConsoleTerminateEvent $event)
Expand Down
4 changes: 2 additions & 2 deletions Tests/EventListener/ErrorListenerTest.php
Expand Up @@ -33,7 +33,7 @@ public function testOnConsoleError()
$logger = $this->createMock(LoggerInterface::class);
$logger
->expects($this->once())
->method('error')
->method('critical')
->with('Error thrown while running command "{command}". Message: "{message}"', ['exception' => $error, 'command' => 'test:run --foo=baz buzz', 'message' => 'An error occurred'])
;

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

Expand Down

0 comments on commit 1a9570e

Please sign in to comment.