Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Console] Add silent verbosity suppressing all output, including errors#53632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged

Conversation

@wouterj
Copy link
Member

@wouterjwouterj commentedJan 25, 2024
edited by OskarStark
Loading

QA
Branch?7.2
Bug fix?no
New feature?yes
Deprecations?yes
IssuesFix#52777
LicenseMIT
Original PR description

Alternative to#53126

In Symfony 2.8, we decided to still show exceptions/errors when running a command with--quiet orSHELL_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).

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 passingNullOutput to the command in silent mode or not ignoring everything written to silent mode inOutput. In the end, I've decided for the last to avoid bug reports from people silently expecting aConsoleOutputInterface in their commands (e.g. for sections) without properly guarding it.

The newisSilent() methods can be used by commands to e.g. write important messages to the logger instead of command output when running in silent mode.

dmaicher and greg0ire reacted with thumbs up emoji
Copy link
Member

@chalasrchalasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Makes sense to me. Should we document it as a BC break given the behavior change is not opt-in?

@wouterj
Copy link
MemberAuthor

I'm not sure, I don't think we want to call this a BC break (or tag it as such) to give the wrong impression that command output is considered within the BC promise.

Let's also friendly ping@Seldaek who implemented the existing logic of showing errors during quiet verbosity. Do you remember a use-case for this? (something with Composer maybe?) Is there something we should take in mind before merging this PR?

@Seldaek
Copy link
Member

IMO it is better to keep displaying it at least if you have a ConsoleOutputInterface where you can output on stderr. Any machine readable output would generally be expected on stdout. By default it will output to stderr so it won't disturb anything.

So I personally would close this, because yes when running quiet in some script/CI and something major breaks and you do not see it at all, it sucks. But that's just my view of course.

@Seldaek
Copy link
Member

Note: I see the point about logging duplicating things, that's not great indeed. I am not sure how else this could be mitigated. I don't really see a way to safely do this, and IMO duplicating uncaught exception sure not great but still better as not seeing them at all.

@wouterj
Copy link
MemberAuthor

wouterj commentedJan 30, 2024
edited
Loading

I get your point about stderr, however both stderr and stdout of processes are redirected to a container's output. So in hosting relying on containers, this is still an issue.

There are utils/techniques you can apply to hide the output of a command, but still get errors (based on exit codes). E.g. in the past, I've used the littlechronic bash utility for this in our CI. And you can also use bash one-liners likeoutput=`mycommand 2>&1` || echo $output to accomplish this.

@Seldaek
Copy link
Member

Ok, then I guess all I can ask is to maybe make this optional so that apps that are pure CLI apps like Composer and not 12-factor style symfony envs with full logger config could maybe retain the quiet-level output?

@nicolas-grekasnicolas-grekas modified the milestones:7.1,7.2May 16, 2024
@nicolas-grekas
Copy link
Member

Let's resume this PR?

@wouterj
Copy link
MemberAuthor

wouterj commentedSep 6, 2024
edited
Loading

Yes please :)

We need to make a decision (@symfony/mergers):

A)Make--quiet completely silent, also for errors (the current state of this PR).
This is a bit troubling for applications currently relying on seeing errors when running with quiet verbosity.
It however is much more compatible with 99% of the CLI tools in the world. Only getting output on error is still possible using the techniques I shared before.

B)Add a new verbosity (e.g.SHELL_VERBOSITY=-2) that disables error output.
No change of existing behavior, but introduces more work (and also requires discoverability) to get truly silent output like you get with other CLI tools.
Optionally, we might add some code in thebin/console recipe to default to-2 when using--quiet to remove this extra barrier for upgraded applications.

@stof
Copy link
Member

stof commentedSep 6, 2024

@wouterj using2 > &1 and then complaining that it screws the processing of the output is void, as the screwing comes from the2 > &1, not from using stderr propertly in the first place.

Thus, cases that want to process the command output programmatically are probably not using--quiet anyway (as there would be not output to process)

@javiereguiluz
Copy link
Member

@wouter I looked in other projects and some commands use special options for this:

About your proposals, I like this one -->Add a new verbosity (e.g. SHELL_VERBOSITY=-2) that disables error output

But, I wouldn't do this:

Optionally, we might add some code in the bin/console recipe to default to -2 when using --quiet to remove this extra barrier for upgraded applications.

Having--quiet silently associated to a new verbosity different than quiet might look convenient but it might bite us in the future.

About possible naming of this new constant, AI suggestedsilent because "quiet" means that makes little or no noise and "silent" means that all noise is suppressed:

Console optionSHELL_VERBOSITY valueEquivalent PHP constant
--silent-2OutputInterface::VERBOSITY_SILENT
-q or--quiet-1OutputInterface::VERBOSITY_QUIET
(none)0OutputInterface::VERBOSITY_NORMAL
-v1OutputInterface::VERBOSITY_VERBOSE
-vv2OutputInterface::VERBOSITY_VERY_VERBOSE
-vvv3OutputInterface::VERBOSITY_DEBUG
chalasr reacted with thumbs up emoji

@kbond
Copy link
Member

About possible naming of this new constant, AI suggested silent because "quiet" means that makes little or no noise and "silent" means that all noise is suppressed:

This makes sense to me. +1 for--silent from me.

chalasr and OskarStark reacted with thumbs up emoji

@fabpot
Copy link
Member

Funnily enough, I encountered this issue yesterday. I was annoyed by the fact--quiet still displays the error. I wanted to remove all output and just rely on$?/$status to understand if the command failed.

Having a new--silent flag sounds like a good compromise. I'm 👍

@OskarStark
Copy link
Contributor

silent 🤫 is better wording 👌🏻

@wouterjwouterjforce-pushed theissue-52777/no-errors-when-quiet branch from1c76cfb to5994816CompareSeptember 19, 2024 12:29
@wouterjwouterj changed the title[Console] Hide errors during quiet verbosity[Console] Add silent verbosity suppressing all output, including errorsSep 19, 2024
@wouterjwouterjforce-pushed theissue-52777/no-errors-when-quiet branch from5994816 to5a16a22CompareSeptember 19, 2024 12:37
@wouterj
Copy link
MemberAuthor

wouterj commentedSep 19, 2024
edited
Loading

Thanks for the feedback everyone!

PR is now updated with a new--silent option. Decided to not add a shortcut (-s), as this can be quite conflicting with shortcut options defined by commands (and Symfony itself already uses it in theCompleteCommand). Besides, when reading this discussion, the new mode is a special programmatic case anyways and we recommend people running commands manually to keep using-q instead.

javiereguiluz reacted with thumbs up emoji

@wouterjwouterjforce-pushed theissue-52777/no-errors-when-quiet branch 2 times, most recently from76991c3 tocd21a93CompareSeptember 19, 2024 12:57
@wouterjwouterjforce-pushed theissue-52777/no-errors-when-quiet branch 2 times, most recently fromdbc370c to51e2856CompareSeptember 19, 2024 13:23
@wouterj
Copy link
MemberAuthor

Low deps failure is unrelated, flipped test failure will be fixed by#58320 if I understand correctly.

Copy link
Member

@kbondkbond left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is still considered a BC break?

@wouterj
Copy link
MemberAuthor

@kbond adding a new global option is always a BC break, as it'll break commands that defined this option before (you'll get an exception when registering that command).
I consider it a "minor backwards compatibility" that we allow in minor versions, but I thought it was good to flag it as BC break in the UPGRADE guide for better visibility.

kbond and OskarStark reacted with thumbs up emojiBafS reacted with confused emoji

@wouterjwouterjforce-pushed theissue-52777/no-errors-when-quiet branch from51e2856 toe7ebf8eCompareSeptember 19, 2024 14:45
fabpot added a commit that referenced this pull requestSep 21, 2024
…troduced in Symfony 7.2 (wouterj)This PR was merged into the 6.4 branch.Discussion----------[Runtime] Adapt test to support the `--silent` option introduced in Symfony 7.2| Q             | A| ------------- | ---| Branch?       | 6.4| Bug fix?      | no| New feature?  | no| Deprecations? | no| Issues        | -| License       | MITPrepare tests for#53632Commits-------bc5ae53 [Runtime] Adapt test to support the --silent option introduced in Symfony 7.2
@wouterjwouterjforce-pushed theissue-52777/no-errors-when-quiet branch frome7ebf8e to57fe0bdCompareSeptember 21, 2024 09:40
@fabpot
Copy link
Member

Thank you@wouterj.

@fabpotfabpot merged commita18ed8f intosymfony:7.2Sep 21, 2024
@wouterjwouterj deleted the issue-52777/no-errors-when-quiet branchSeptember 21, 2024 12:55
@fabpotfabpot mentioned this pull requestOct 27, 2024
LukeTowers added a commit to wintercms/winter that referenced this pull requestJul 25, 2025
symfony/symfony#53632 made it so that the --silent option is now provided & managed by the symfony core itself which would have been all well and good, except for the fact that sincesymfony/symfony#24425 symfony has been persisting the selected verbosity layer in the environment. This means that if you have a test that calls a command with the --silent flag set, and then it's followed by a test that relies on the --silent flag not being set, that second test (and any future test that expects the --silent flag not to be set) will also fail.This leads to all sorts of headaches around tests failing depending on the order they are run in, whether or not you're running a single test case or multiple, or even whether the environment you're running the tests in actually supports putenv().Massive credit to@jaxwilko for finding the issue and coming up with the solution.
bennothommo pushed a commit to wintercms/wn-system-module that referenced this pull requestJul 25, 2025
symfony/symfony#53632 made it so that the --silent option is now provided & managed by the symfony core itself which would have been all well and good, except for the fact that sincesymfony/symfony#24425 symfony has been persisting the selected verbosity layer in the environment. This means that if you have a test that calls a command with the --silent flag set, and then it's followed by a test that relies on the --silent flag not being set, that second test (and any future test that expects the --silent flag not to be set) will also fail.This leads to all sorts of headaches around tests failing depending on the order they are run in, whether or not you're running a single test case or multiple, or even whether the environment you're running the tests in actually supports putenv().Massive credit to@jaxwilko for finding the issue and coming up with the solution.
nicolas-grekas added a commit that referenced this pull requestSep 9, 2025
…at SILENT verbosity (okhoshi)This PR was merged into the 7.3 branch.Discussion----------[MonologBridge] Make `ConsoleHandler` not handle messages at SILENT verbosity| Q             | A| ------------- | ---| Branch?       | 7.3| Bug fix?      | yes| New feature?  | no| Deprecations? | no| Issues        |#53632| License       | MIT<details><summary>Original description</summary><p>Adding a new constructor parameter to ConsoleHandler to let it bubble messages when the output is set at Silent verbosity level (like when using `--silent` in the CLI).Messages are dropped by the ConsoleHandler down the line because of the verbosity, but they are considered as handled and so bubbling is interrupted if the handler is set with `$bubble = false`. The use-case is to have the messages being either printed by the ConsoleHandler (and so seen by the person running the CLI) or sent to the logging system by the next handlers, but not both.Tweaking the `$verbosityLevelMap` is not perfect because EMERGENCY level can never be marked as not handled.With this change, the behaviour is more consistent between Silent and Quiet verbosity levels.</p></details>Messages are dropped by the ConsoleHandler down the line because of the verbosity, but they are considered as handled and so bubbling is interrupted if the handler is set with `$bubble = false`. The use-case is to have the messages being either printed by the ConsoleHandler (and so seen by the person running the CLI) or sent to the logging system by the next handlers, but not both.By not handling messages when the ConsoleHandler verbosity is set to silent, the behaviour is more consistent between, Silent and all the other verbosity levels.Commits-------c7e655d [MonologBridge] Make `ConsoleHandler` not handle messages at SILENT verbosity
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@stofstofstof left review comments

@fabpotfabpotfabpot approved these changes

@javiereguiluzjaviereguiluzjaviereguiluz approved these changes

@kbondkbondkbond approved these changes

@OskarStarkOskarStarkOskarStark approved these changes

@chalasrchalasrchalasr approved these changes

+1 more reviewer

@SeldaekSeldaekSeldaek left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Projects

None yet

Milestone

7.2

Development

Successfully merging this pull request may close these issues.

Allow disabling exception rendering

10 participants

@wouterj@Seldaek@nicolas-grekas@stof@javiereguiluz@kbond@fabpot@OskarStark@chalasr@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp