fix(logger): inject --verbose and --log-level as proper Stricli flags#353
Merged
fix(logger): inject --verbose and --log-level as proper Stricli flags#353
Conversation
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Trace
Other
Bug Fixes 🐛Api
Formatters
Setup
Upgrade
Other
Documentation 📚
Internal Changes 🔧Api
Other
🤖 This preview updates automatically when you update the PR. |
Contributor
|
4d269d9 to
4ba8061
Compare
7b527e3 to
c21f22c
Compare
Contributor
Codecov Results 📊✅ 101 passed | Total: 101 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 3675 uncovered lines. Files with missing lines (2)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 80.67% 80.75% +0.08%
==========================================
Files 127 127 —
Lines 19052 19091 +39
Branches 0 0 —
==========================================
+ Hits 15369 15416 +47
- Misses 3683 3675 -8
- Partials 0 0 —Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Fix three bugs in the logging system introduced in #338: 1. `--verbose` rejected by all commands except `api` — Stricli throws "No flag registered for --verbose" because extractLogLevelFromArgs intentionally left it in argv for the api command. 2. `--log-level=debug` (equals form) not handled — argv.indexOf only matched the space-separated form, passing the flag through to Stricli. 3. `SENTRY_LOG_LEVEL` env var has no visible effect — consola withTag() creates independent instances that snapshot the level at creation time. Module-level scoped loggers never saw later setLogLevel() calls. Instead of pre-parsing flags from argv (bypassing Stricli), define them as proper hidden Stricli flags. buildCommand in src/lib/command.ts now wraps Stricli to inject hidden --log-level (enum) and --verbose (boolean) flags into every command, intercept them, apply setLogLevel(), then strip them before calling the original func. When a command already defines its own --verbose (e.g. api uses it for HTTP output), the injected one is skipped — the command own value still triggers debug-level logging as a side-effect. setLogLevel() now propagates to all withTag() children via a registry, fixing the env var and flag having no effect on scoped loggers. Document SENTRY_LOG_LEVEL, --log-level, and --verbose in configuration docs.
c21f22c to
bd8f92c
Compare
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix three bugs in the logging system introduced in #338:
--verboserejected by all commands exceptapi— Stricli throws "No flag registered for --verbose" becauseextractLogLevelFromArgsleft it in argv.--log-level=debug(equals form) broken —argv.indexOf("--log-level")only matched the space-separated form.SENTRY_LOG_LEVELenv var has no visible effect — consolawithTag()creates independent instances that snapshot the level at creation time; module-level scoped loggers never saw latersetLogLevel()calls.Approach
Stricli doesn't support global flags (bloomberg/stricli#106, closed as not planned). Instead of pre-parsing flags from argv (which bypasses Stricli's strict validation), we define them as proper hidden Stricli flags injected via a
buildSentryCommand()wrapper.buildSentryCommand()(src/lib/command.ts)buildCommandto inject hidden--log-level(enum) and--verbose(boolean) flagsfunc, appliessetLogLevel(), strips thembuildSentryCommandinstead ofbuildCommandapicommand keepsbuildCommanddirectly (it has its own--verbosewith HTTP semantics) and addsLOG_LEVEL_FLAGmanuallywithTag()level propagation (src/lib/logger.ts)logger.withTag()is wrapped to register all child loggers in a registrysetLogLevel()propagates the level to all registered childrenDocumentation (
docs/configuration.md)SENTRY_LOG_LEVELenv var documentation--log-leveland--verboseTest plan
command.test.ts,logger.test.ts,logger.property.test.ts— all pass--verbose,--log-level=debug,SENTRY_LOG_LEVEL=debugall work without errors