Skip to content

fix(logger): inject --verbose and --log-level as proper Stricli flags#353

Merged
BYK merged 1 commit intomainfrom
byk/fix-logging-flags
Mar 5, 2026
Merged

fix(logger): inject --verbose and --log-level as proper Stricli flags#353
BYK merged 1 commit intomainfrom
byk/fix-logging-flags

Conversation

@BYK
Copy link
Member

@BYK BYK commented Mar 5, 2026

Summary

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 left it in argv.
  2. --log-level=debug (equals form) brokenargv.indexOf("--log-level") only matched the space-separated form.
  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.

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)

  • Wraps buildCommand to inject hidden --log-level (enum) and --verbose (boolean) flags
  • Intercepts these flags before calling the original func, applies setLogLevel(), strips them
  • All commands now use buildSentryCommand instead of buildCommand
  • The api command keeps buildCommand directly (it has its own --verbose with HTTP semantics) and adds LOG_LEVEL_FLAG manually

withTag() level propagation (src/lib/logger.ts)

  • logger.withTag() is wrapped to register all child loggers in a registry
  • setLogLevel() propagates the level to all registered children
  • Fixes the env var and CLI flags having no effect on scoped loggers

Documentation (docs/configuration.md)

  • Added SENTRY_LOG_LEVEL env var documentation
  • Added "Global Options" section documenting --log-level and --verbose

Test plan

  • 51 tests across command.test.ts, logger.test.ts, logger.property.test.ts — all pass
  • Manual verification: --verbose, --log-level=debug, SENTRY_LOG_LEVEL=debug all work without errors

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

Semver Impact of This PR

🟢 Patch (bug fixes)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


New Features ✨

Trace

Other

  • (api) Add --data/-d flag and auto-detect JSON body in fields by BYK in #320
  • (formatters) Render all terminal output as markdown by BYK in #297
  • (install) Add Sentry error telemetry to install script by BYK in #334
  • (issue-list) Global limit with fair distribution, compound cursor, and richer progress by BYK in #306
  • (log-list) Add --trace flag to filter logs by trace ID by BYK in #329
  • (logger) Add consola-based structured logging with Sentry integration by BYK in #338
  • (project) Add project create command by betegon in #237
  • (upgrade) Add binary delta patching via TRDIFF10/bsdiff by BYK in #327
  • Improve markdown rendering styles by BYK in #342

Bug Fixes 🐛

Api

  • Use numeric project ID to avoid "not actively selected" error by betegon in #312
  • Use limit param for issues endpoint page size by BYK in #309
  • Auto-correct ':' to '=' in --field values with a warning by BYK in #302

Formatters

  • Expand streaming table to fill terminal width by betegon in #314
  • Fix HTML entities and escaped underscores in table output by betegon in #313

Setup

  • Suppress agent skills and welcome messages on upgrade by BYK in #328
  • Suppress shell completion messages on upgrade by BYK in #326

Upgrade

  • Check GHCR for nightly version existence instead of GitHub Releases by BYK in #352
  • Replace Bun.mmap with arrayBuffer on all platforms by BYK in #343
  • Replace Bun.mmap with arrayBuffer on macOS to prevent SIGKILL by BYK in #340
  • Use MAP_PRIVATE mmap to prevent macOS SIGKILL during delta upgrade by BYK in #339

Other

  • (ci) Generate JUnit XML to silence codecov-action warnings by BYK in #300
  • (install) Fix nightly digest extraction on macOS by BYK in #331
  • (logger) Inject --verbose and --log-level as proper Stricli flags by BYK in #353
  • (nightly) Push to GHCR from artifacts dir so layer titles are bare filenames by BYK in #301
  • (project create) Auto-correct dot-separated platform to hyphens by BYK in #336
  • (region) Resolve DSN org prefix at resolution layer by BYK in #316
  • (test) Handle 0/-0 in getComparator anti-symmetry property test by BYK in #308
  • (trace-logs) Timestamp_precise is a number, not a string by BYK in #323

Documentation 📚

  • Document SENTRY_URL and self-hosted setup by BYK in #337

Internal Changes 🔧

Api

  • Upgrade @sentry/api to 0.21.0, remove raw HTTP pagination workarounds by BYK in #321
  • Wire listIssuesPaginated through @sentry/api SDK for type safety by BYK in #310

Other

  • (craft) Add sentry-release-registry target by BYK in #325
  • (project create) Migrate human output to markdown rendering system by BYK in #341
  • (upgrade) Use copy-then-mmap for zero JS heap during delta patching by BYK in #344

🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

PR Preview Action v1.8.1

QR code for preview link

🚀 View preview at
https://cli.sentry.dev/pr-preview/pr-353/

Built to branch gh-pages at 2026-03-05 14:16 UTC.
Preview will be ready when the GitHub Pages deployment is complete.

@BYK BYK force-pushed the byk/fix-logging-flags branch 2 times, most recently from 4d269d9 to 4ba8061 Compare March 5, 2026 13:49
@BYK BYK marked this pull request as ready for review March 5, 2026 13:57
@BYK BYK force-pushed the byk/fix-logging-flags branch 2 times, most recently from 7b527e3 to c21f22c Compare March 5, 2026 14:08
@github-actions
Copy link
Contributor

github-actions bot commented Mar 5, 2026

Codecov Results 📊

101 passed | Total: 101 | Pass Rate: 100% | Execution Time: 0ms

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 3675 uncovered lines.
✅ Project coverage is 80.75%. Comparing base (base) to head (head).

Files with missing lines (2)
File Patch % Lines
help.ts 58.33% ⚠️ 15 Missing
logger.ts 85.00% ⚠️ 9 Missing
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

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

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.
@BYK BYK force-pushed the byk/fix-logging-flags branch from c21f22c to bd8f92c Compare March 5, 2026 14:15
@BYK BYK merged commit 45f3888 into main Mar 5, 2026
21 checks passed
@BYK BYK deleted the byk/fix-logging-flags branch March 5, 2026 14:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant