cli: set default verbosity level with environment variable
Metadata
Current evaluation
Merged #3958 as commit 010fd708d, adding SNAPCRAFT_VERBOSITY_LEVEL defaults for quiet, brief, verbose, debug, and trace logging.
Resolution: closed resolved
Reason: PR #3958 was approved and merged to Snapcraft main as commit 010fd708d. Known flag-precedence and duplicate-greeting behavior was documented separately in canonical/craft-cli#128.
Evaluated by: mr-cal-bot
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 |
|---|---|---|---|---|
| stealth/space-bunny-alpha | — | closed resolved | Merged #3958 as commit 010fd708d, adding SNAPCRAFT_VERBOSITY_LEVEL defaults for quiet, brief, verbose, debug, and trace logging. | |
| stealth/space-bunny-alpha | — | closed resolved | Merged PR #3958 (commit 010fd708d), adding SNAPCRAFT_VERBOSITY_LEVEL. Duplicate greetings and explicit-flag precedence issues were documented and tracked in craft-cli#128. | |
| 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. |
Update history
No update history recorded yet.
Related work
-
Blocked By:
canonical/craft-cli#128
(confidence 95%)
The PR explicitly raised this craft-cli issue for better pre-parsing and verbosity handling.
-
Related To:
canonical/snapcraft#4699
(confidence 90%)
Merged as 2fd361741 to map SNAPCRAFT_VERBOSITY_LEVEL to CRAFT_VERBOSITY_LEVEL after Craft-based logging was introduced.
Related issues
| Issue | Project | State | Summary | Similarity |
|---|---|---|---|---|
| #1988065 Default verbosity level should be configurable | snapcraft (launchpad) | closed | Added SNAPCRAFT_VERBOSITY_LEVEL for persistent default output verbosity in snapcraft#3958 (commit 010fd708d). | |
| #4647 Setting verbosity via environment variable no longer works on 8.0.4.post33+git61228836 | snapcraft | closed | SNAPCRAFT_VERBOSITY_LEVEL stopped working after the craft-application migration; fixed in snapcraft PR #4699 (commit 283d44301 / merge 2fd361741) by mapping it to CRAFT_VERBOSITY_LEVEL. Reporter confirmed the fix. | |
| #289 fix(log): allows set logging verbosity level from env | craft-application | merged | Merged PR #289 added CRAFT_VERBOSITY_LEVEL support for log emitter verbosity, defaulting to BRIEF for invalid values; landed as commit 226fd102. | |
| #5646 feat(snapcraft_legacy): support verbosity args | snapcraft | merged | Merged as commit 3aeded2fa: snapcraft_legacy core20 commands now accept craft-cli verbosity args/env vars, with --enable-developer-debug as alias for --verbosity=debug. Follow-up #5680 (4a7663069) extended it to non-lifecycle commands. |