You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feature #53632 [Console] Add silent verbosity suppressing all output, including errors (wouterj)
This PR was merged into the 7.2 branch.
Discussion
----------
[Console] Add silent verbosity suppressing all output, including errors
| Q | A
| ------------- | ---
| Branch? | 7.2
| Bug fix? | no
| New feature? | yes
| Deprecations? | yes
| Issues | Fix#52777
| License | MIT
<details>
<summary>Original PR description</summary>
Alternative to #53126
In Symfony 2.8, we decided to still show exceptions/errors when running a command with `--quiet` or `SHELL_VERBOSITY=-1` (#15680).
Since that time, we've introduced the ConsoleLogger and 12-factor app logic. In todays landscape, it's more common to run commands that only output computer-readable text (e.g. JSON), which is ingested and displayed by services like Datadog and Kibana.
Our decision from 2.8 breaks this, as the JSON is interrupted by human-readable exception output that users can't disable. At the same time, this information is duplicated as errors are always logged (and thus shown as JSON).
I think we should revert the 2.8 decision, rather than adding a new "extremely quiet" verbosity mode. As far as I'm aware, this is also more consistent with normal unix commands which also don't output anything when passing `--quiet`.
I don't think this warrants as a BC break, as the errors are human readable and we don't promise BC on human readable console output (afaik, we don't promise BC on any console output, but I think we should be careful when changing e.g. the JSON logging).
</details>
This updated PR adds a new `--silent` verbosity mode that suppresses all output, including exceptions caught by the Application.
I went back and forth between simply passing `NullOutput` to the command in silent mode or not ignoring everything written to silent mode in `Output`. In the end, I've decided for the last to avoid bug reports from people silently expecting a `ConsoleOutputInterface` in their commands (e.g. for sections) without properly guarding it.
The new `isSilent()` methods can be used by commands to e.g. write important messages to the logger instead of command output when running in silent mode.
Commits
-------
57fe0bd [Console] Add silent verbosity mode suppressing all output, including errors
@@ -946,7 +952,7 @@ protected function configureIO(InputInterface $input, OutputInterface $output):
946
952
}
947
953
}
948
954
949
-
if (-1 ===$shellVerbosity) {
955
+
if (0 >$shellVerbosity) {
950
956
$input->setInteractive(false);
951
957
}
952
958
@@ -1082,7 +1088,8 @@ protected function getDefaultInputDefinition(): InputDefinition
1082
1088
returnnewInputDefinition([
1083
1089
newInputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
1084
1090
newInputOption('--help', '-h', InputOption::VALUE_NONE, 'Display help for the given command. When no command is given display help for the <info>'.$this->defaultCommand.'</info> command'),
1085
-
newInputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'),
1091
+
newInputOption('--silent', null, InputOption::VALUE_NONE, 'Do not output any message'),
1092
+
newInputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Only errors are displayed. All other output is suppressed'),
1086
1093
newInputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
1087
1094
newInputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version'),
$this->assertStringContainsString('Exception trace', $tester->getErrorOutput(), '->renderException() renders a pretty exception with a stack trace when verbosity is verbose');
$this->assertStringEqualsFile(self::$fixturesPath.'/application_renderexception2.txt', $tester->getErrorOutput(true), '->renderException() renders the command synopsis when an exception occurs in the context of a command');
0 commit comments