← Back to issue list

cli: set default verbosity level with environment variable

View original Github issue

Metadata

Project
snapcraft
Number
#3958
Type
pull request
State
merged
Author
mr-cal
Labels
Created
Updated
Closed

Current evaluation

Merged. Adds SNAPCRAFT_VERBOSITY_LEVEL env var for default CLI verbosity. Author noted implementation flaws causing duplicate logs and precedence issues, opening craft-cli issue #128 for a proper fix.

Suggested action:

No scores available.

Issue body

- [X] Have you followed the [guidelines for contributing](https://github.com/snapcore/snapcraft/blob/master/CONTRIBUTING.md)? - [X] Have you signed the [CLA](http://www.ubuntu.com/legal/contributors/)? - [x] Have you successfully run `make lint`? - [x] Have you successfully run `pytest tests/unit`? ----- The default verbosity level can be set with the environment variable `SNAPCRAFT_VERBOSITY_LEVEL`, where valid values are `quiet`, `brief`, `verbose`, `debug`, and `trace`. The implementation I chose for this PR isn't correct. Running `SNAPCRAFT_VERBOSITY_LEVEL=trace snapcraft pull --verbosity=quiet` produces the output ``` 2022-10-24 15:36:28.919 Starting Snapcraft 7.1.1.post1+git6934c0ba 2022-10-24 15:36:28.919 Logging execution to '/home/developer/.cache/snapcraft/log/snapcraft-20221024-153628.919185.log' ``` Running `SNAPCRAFT_VERBOSITY_LEVEL=trace snapcraft pull --verbosity=trace` outputs the greeting message twice: ``` 2022-10-24 15:36:44.269 Starting Snapcraft 7.1.1.post1+git6934c0ba 2022-10-24 15:36:44.269 Logging execution to '/home/developer/.cache/snapcraft/log/snapcraft-20221024-153644.268436.log' 2022-10-24 15:36:44.269 Starting Snapcraft 7.1.1.post1+git6934c0ba 2022-10-24 15:36:44.269 Logging execution to '/home/developer/.cache/snapcraft/log/snapcraft-20221024-153644.268436.log' 2022-10-24 15:36:44.269 Raw pre-parsed sysargs: args={'help': False, 'verbose': False, 'quiet': False, 'verbosity': 'trace', 'version': False, 'trace': False} filtered=['pull'] 2022-10-24 15:36:44.269 General parsed sysargs: command='pull' args=[] ... (logs continue in 'trace' mode) ``` I'd like to talk to @facundobatista this week about a better solution. I'm thinking about adding an optional parameter to `craft_cli.dispatcher.pre_parse_args()`. Another option would be allowing snapcraft to call `pre_parse_args()` (or another subset of this method) to parse the verbosity level before initializing the emitter. Update: Facundo and I talked about a solution and raised a non-blocking craft-cli issue: https://github.com/canonical/craft-cli/issues/128 (CRAFT-1420)

Evaluation history

Date Model Scores Action Summary
qwen/qwen3.6-35b-a3b Merged. Adds SNAPCRAFT_VERBOSITY_LEVEL env var for default CLI verbosity. Author noted implementation flaws causing duplicate logs and precedence issues, opening craft-cli issue #128 for a proper fix.
qwen3.6-35b-a3b-mtp-q6 Merged. Adds SNAPCRAFT_VERBOSITY_LEVEL to set default CLI verbosity. Conflicts with explicit flags and duplicate logs were noted, deferring a robust fix to craft-cli issue #128. Achieved 100% diff coverage.
qwen3.6-35b-a3b-mtp-q6 Merged PR adding SNAPCRAFT_VERBOSITY_LEVEL environment variable to set default CLI verbosity. Implementation flaws were acknowledged and tracked via upstream craft-cli issue #128. Coverage increased by 0.01%.

Update history

No update history recorded yet.

Related issues

Issue Project State Summary Similarity
#264 Support CRAFT_VERBOSITY_LEVEL craft-application closed Added support for the CRAFT_VERBOSITY_LEVEL environment variable to configure initial verbosity, matching Snapcraft's implementation. The change was merged via pull request #289 in the craft-application repository.
78%
#289 fix(log): allows set logging verbosity level from env craft-application merged Merged changes that enable log verbosity configuration via the CRAFT_VERBOSITY_LEVEL environment variable, defaulting to BRIEF on invalid input. Approved by two reviewers, passed CI, and updated two files.
75%
#4647 Setting verbosity via environment variable no longer works on 8.0.4.post33+git61228836 snapcraft closed The SNAPCRAFT_VERBOSITY_LEVEL environment variable was ignored because craft-application and snapcraft did not read or forward it. Merging pull request #4699 restored the functionality. The reporter verified the fix.
75%
#5646 feat(snapcraft_legacy): support verbosity args snapcraft merged Merged. Implements craft-cli verbosity arguments and environment variable support for core20 commands in snapcraft_legacy, preserving --enable-developer-debug alias. Approved by reviewers and resolves #5423.
74%