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

Skip to content

Commit 7010f99

Browse files
author
Robin Chalas
committed
bug #23828 [Console] Log exit codes as debug messages instead of errors (haroldiedema)
This PR was merged into the 3.3 branch. Discussion ---------- [Console] Log exit codes as debug messages instead of errors | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | n/a | License | MIT | Doc PR | n/a Fixes PR #21003 This patch stops logging `exit_codes != 0` to _error_ and logs it to _debug_ instead, since it's not an error. The console application exited without uncaught exceptions, and the console application deliberately returned a specific exit code, therefore it shouldn't be logged as an error. A valid use case would be to let a caller script in bash (the script spawning the console command) know what action to take based on the exit code. More specifically, exit codes other than 1, 2, 127+n isn't necessarily considered an error. Monolog is hooked to our mailbox, so we can see what is happening in our production environment. However, it's currently being spammed for no reason because of #21003. tl;dr: user-programmed exit codes (return <int> in `execute()`) should NOT log an error message to monolog. I find it a bit iffy to leave the `console.terminiate` event listener in since it now logs to `debug` instead. I'm unsure if people want/need this, so I might as well remove the terminate listener entirely. Commits ------- cadbed3 [Console] Log exit codes as debug messages instead of errors
2 parents 91332a0 + cadbed3 commit 7010f99

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ public function onConsoleTerminate(ConsoleTerminateEvent $event)
5959
}
6060

6161
if (!$inputString = $this->getInputString($event)) {
62-
return $this->logger->error('The console exited with code "{code}"', array('code' => $exitCode));
62+
return $this->logger->debug('The console exited with code "{code}"', array('code' => $exitCode));
6363
}
6464

65-
$this->logger->error('Command "{command}" exited with code "{code}"', array('command' => $inputString, 'code' => $exitCode));
65+
$this->logger->debug('Command "{command}" exited with code "{code}"', array('command' => $inputString, 'code' => $exitCode));
6666
}
6767

6868
public static function getSubscribedEvents()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testOnConsoleTerminateForNonZeroExitCodeWritesToLog()
6161
$logger = $this->getLogger();
6262
$logger
6363
->expects($this->once())
64-
->method('error')
64+
->method('debug')
6565
->with('Command "{command}" exited with code "{code}"', array('command' => 'test:run', 'code' => 255))
6666
;
6767

@@ -74,7 +74,7 @@ public function testOnConsoleTerminateForZeroExitCodeDoesNotWriteToLog()
7474
$logger = $this->getLogger();
7575
$logger
7676
->expects($this->never())
77-
->method('error')
77+
->method('debug')
7878
;
7979

8080
$listener = new ErrorListener($logger);
@@ -97,7 +97,7 @@ public function testAllKindsOfInputCanBeLogged()
9797
$logger = $this->getLogger();
9898
$logger
9999
->expects($this->exactly(3))
100-
->method('error')
100+
->method('debug')
101101
->with('Command "{command}" exited with code "{code}"', array('command' => 'test:run --foo=bar', 'code' => 255))
102102
;
103103

@@ -112,7 +112,7 @@ public function testCommandNameIsDisplayedForNonStringableInput()
112112
$logger = $this->getLogger();
113113
$logger
114114
->expects($this->once())
115-
->method('error')
115+
->method('debug')
116116
->with('Command "{command}" exited with code "{code}"', array('command' => 'test:run', 'code' => 255))
117117
;
118118

0 commit comments

Comments
 (0)