Skip to content

[Console][HttpKernel] Handle new SHELL_VERBOSITY env var, also configures the default logger #24425

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2017

Conversation

nicolas-grekas
Copy link
Member

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

On the CLI, the behavior of the new default logger is not nice: it's verbosity is controlled by kernel.debug, where I would expect to be able to control it by mean of verbosity.
To achieve this, I propose to handle a new SHELL_VERBOSITY env var, and use it to control both commands' verbosity, and the logger's log level.

@nicolas-grekas nicolas-grekas added this to the 3.4 milestone Oct 4, 2017
@nicolas-grekas nicolas-grekas force-pushed the default-logger branch 2 times, most recently from 19e975e to de0838b Compare October 4, 2017 16:04
@nicolas-grekas nicolas-grekas changed the title [Console][HttpKernel] Handle new SHELL_VERBOSITY env var to control, also configures the default logger [Console][HttpKernel] Handle new SHELL_VERBOSITY env var, also configures the default logger Oct 4, 2017
@nicolas-grekas nicolas-grekas force-pushed the default-logger branch 5 times, most recently from fcaac72 to 630d5dd Compare October 4, 2017 16:33
@GromNaN
Copy link
Member

GromNaN commented Oct 5, 2017

The Console\Application class is doing a side effect on environment variables for usage in one implementation of the Logger.

Reading and writing global variables inside classes looks like a bad practice. This should be delegated to a config/context layer.

@nicolas-grekas
Copy link
Member Author

nicolas-grekas commented Oct 5, 2017

@GromNaN it's not exactly for that, but to create an environment context that mirrors the -vvv verbosity flags. Then this context is leveraged by the logger yes, but this is independent (you could set the env var in a webserver context to control the logger's verbosity also.)
I don't have much better idea for now that wouldn't imply a pile of code we don't need nor want.

@fabpot
Copy link
Member

fabpot commented Oct 10, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 87bd741 into symfony:3.4 Oct 10, 2017
fabpot added a commit that referenced this pull request Oct 10, 2017
…ar, also configures the default logger (nicolas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[Console][HttpKernel] Handle new SHELL_VERBOSITY env var, also configures the default logger

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

On the CLI, the behavior of the new default logger is not nice: it's verbosity is controlled by `kernel.debug`, where I would expect to be able to control it by mean of verbosity.
To achieve this, I propose to handle a new `SHELL_VERBOSITY` env var, and use it to control both commands' verbosity, and the logger's log level.

Commits
-------

87bd741 [Console][HttpKernel] Handle new SHELL_VERBOSITY, also configures the default logger
@nicolas-grekas nicolas-grekas deleted the default-logger branch October 10, 2017 20:11
This was referenced Oct 18, 2017
@alexislefebvre
Copy link
Contributor

TLDR: the value in $output->getVerbosity() is overwritten in the switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) {…} block added in this PR, is it an unexpected site effect?


It looks like this PR overwrites the verbosity level set by calling setVerbosity(). Maybe this wasn't a good idea though.

Anyway, here is how we used it in LiipFunctionalTestBundle:

  1. we created an Application: https://github.com/liip/LiipFunctionalTestBundle/blob/bf909887fbd3aac10215efeb6f6287c72afc568d/Test/WebTestCase.php#L130
  2. we instantiated a StreamOutput with the verbosity level: https://github.com/liip/LiipFunctionalTestBundle/blob/bf909887fbd3aac10215efeb6f6287c72afc568d/Test/WebTestCase.php#L146 (so we expect StreamOutput->verbosity to contain the expected verbosity value)
  3. we called Application::run(): https://github.com/liip/LiipFunctionalTestBundle/blob/bf909887fbd3aac10215efeb6f6287c72afc568d/Test/WebTestCase.php#L148
  4. this last method calls configureIO that has been changed in this PR: https://github.com/symfony/symfony/pull/24425/files#diff-38eebdda7d6ebfcb7405b91167f05c9c

During my own tests, getenv('SHELL_VERBOSITY') is equal to 3 (I'm still wondering why). So $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); is called and the value in $output->getVerbosity(); is overwritten.

@xabbuh
Copy link
Member

xabbuh commented Dec 8, 2017

During my own tests, getenv('SHELL_VERBOSITY') is equal to 3 (I'm still wondering why).

That's probably because of the Kernel class setting it explicitly if it wasn't set before: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/Kernel.php#L115-L119

For the rest, I suggest to open a new issue if you feel something is not working as expected.

@lisachenko
Copy link

Unexpected result of this PR that CLI commands in debug mode now do not write debug and info logs, because of default value LogLevel::WARNING. I think that for debug mode verbosity should be debug to keep logging all debug lines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants