Repository navigation
feat(cli-logger): Publish the CLI logger as @sentry/cli-logger - #1773
sentry-junior[bot] wants to merge 1 commit into
Conversation
Move the logger from packages/cli/src/lib/logger.ts into a new packages/cli-logger workspace package, published to npm as @sentry/cli-logger. createLogger() takes the CLI-specific pieces as options: env (the CLI passes getEnv for library mode) and prompt (the CLI keeps its completion-build guard around clackPrompt). formatLogTime moves into the package as the default formatLocalTime. The CLI's logger.ts keeps its exports, so callers and test mocks do not change. Releases go through the Release workflow's new cli-logger product. Fixes #1772 Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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.
Reviewed by Cursor Bugbot for commit 3b25814. Configure here.
| end | ||
| packages/cli-logger: | ||
| changelog: | ||
| policy: auto |
There was a problem hiding this comment.
Craft auto changelog lacks CHANGELOG
Medium Severity
The new cli-logger Craft workspace sets changelog.policy to auto, but packages/cli-logger has no CHANGELOG.md. The CLI workspace that uses the same policy keeps that file next to the package. Craft’s prepare step reads and updates it, so the first cli-logger release can fail before npm publish.
Reviewed by Cursor Bugbot for commit 3b25814. Configure here.
There was a problem hiding this comment.
Checked this against Craft: with changelog.policy: auto, prepareChangelog creates the missing file instead of failing (src/commands/prepare.ts: if (!existsSync(relativePath)) { if (changelogPolicy === ChangelogPolicy.Auto) { ... safeFs.writeFile(relativePath, "# Changelog\n") } ...}). That code is in the v3 tag release.yml uses. For a workspace, the default path is <workspace>/CHANGELOG.md (getDefaultChangelogFilePath in src/config.ts), so the first cli-logger release creates packages/cli-logger/CHANGELOG.md and commits it on the release branch. Leaving the config as is.
| echo '{ "private": true, "type": "module" }' > package.json | ||
| npm install --ignore-scripts --no-audit --no-fund "$RUNNER_TEMP"/sentry-cli-logger-*.tgz @clack/prompts@0.11.0 typescript@^5.8.3 @types/node@^22 | ||
|
|
||
| cat > tsconfig.json <<'EOF' |
There was a problem hiding this comment.
Why not make these actual files on the disk??
| @@ -0,0 +1,100 @@ | |||
| name: CLI Logger Package | |||
There was a problem hiding this comment.
Why CLI logger? Is this not a general-purpose Node/Bun etc logger?
| - cli-logger | ||
| - mcp | ||
| bump: | ||
| description: Version bump type |
There was a problem hiding this comment.
Do you think we can make Craft do this without a script? If yes, let's file an issue there?
| For package-specific rules, see the root [AGENTS.md](../AGENTS.md) and the | ||
| [CLI AGENTS.md](../packages/cli/AGENTS.md). `packages/toolkit-core/` contains | ||
| shared primitives used by both products. | ||
| shared primitives used by both products. `packages/cli-logger/` is the CLI's |
There was a problem hiding this comment.
The reason I want to publish this logger as a standalone package is because I think it can be useful to others so naming it cli-logger feels unnecessarily specific.
| * 1. **The stderr reporter** (built in) — renders consola's "fancy" layout | ||
| * (icons, colors, `WARN`/`ERROR` badges, a right-aligned `tag HH:MM:SS`) and | ||
| * falls back to plain `[type] [tag] message` lines in CI and tests. | ||
| * 2. **Any reporter passed to `addReporter()`**, such as |
There was a problem hiding this comment.
I wonder if we can architecture this in a better way:
Start with structured logs with built-in Sentry support (not required and it should not directly depend on any Sentry package -- can be optional peer dependencies or just use debug channels), then add reporters. One being the consola-style fancy, one JSON, and one logfmt.
There was a problem hiding this comment.
Not sure prompting should be part of a logging package. I think this needs to live outside, especially because it also requires an external dependency. Ideally, our logger package will be tiny, type-safe, and dependency-free.
| @@ -0,0 +1,105 @@ | |||
| # Functional Source License, Version 1.1, Apache 2.0 Future License | |||
There was a problem hiding this comment.
I think we can make this one Apache-2 or MIT.
| @@ -0,0 +1,88 @@ | |||
| { | |||
| "name": "@sentry/cli-logger", | |||
| "version": "0.1.0", | |||
| @@ -0,0 +1,140 @@ | |||
| # @sentry/cli-logger | |||
|
|
|||
| A small terminal logger for Node.js command-line tools: log levels, tag scoping, | |||
There was a problem hiding this comment.
Don't forget to update this README based on my other feedback. We should also explain our rationale for coming up with yet another logging library.


Fixes #1772.
Moves the logger from #1771 out of
packages/cli/src/lib/logger.tsinto a newpackages/cli-loggerworkspace package, published to npm as@sentry/cli-logger.Package API
createLogger({ level, env, formatTime, prompt })returns a root logger. ItswithTag()loggers share the root's level and reporter list, as before. Each root has its own state, so the module-level singleton is gone from the package.parseLogLevel,LOG_LEVEL_NAMES,formatLocalTime, and theLogObject/LogReporter/Prompttypes. Records still have consola's shape, soSentry.createConsolaReporter()works withaddReporter().@sentry/cli-logger/promptexportsclackPrompt.@clack/promptsis an optional peer dependency, and the main entry never references it.How the CLI-local pieces were split out
getEnv()→ theenvoption, read on each log call. The CLI passesgetEnv, so library mode's isolated env still controls colors and layout. A CLI test covers this withwithEnv.formatLogTime()→ moved into the package as the defaultformatLocalTime, since only the logger used it. Its tests moved with it.SENTRY_CLI_COMPLETION_BUILD→ stays in the CLI. The CLI'saskUserkeeps the define guard and lazy-imports@sentry/cli-logger/prompt, sodist/complete.cjsstill contains no@clack/prompts. The package itself has no build-time globals.packages/cli/src/lib/logger.tskeeps every export it had, so its ~170 importers and thevi.mockcalls in tests don't change.Packaging and release
exportspoint atsrc/*.ts, liketoolkit-core, so the CLI's esbuild bundle, vitest, and tsc need no build step.publishConfig.exportspoints the packed tarball at the tsdown ESM/CJSdist/, with.d.ts/.d.ctstypes.cli-loggercraft workspace (tag prefixcli-logger@, release branchrelease/cli-logger/*) and acli-loggeroption in the Release workflow. Post-merge jobs now also pack the tarball into the commit's artifact.CLI Logger Packageworkflow: it packs the package, installs it into a clean npm project, typechecks ESM and CJS consumers, and runs both.Decisions to confirm
@sentry/cli-logger. It's free on npm. I avoided@sentry/loggerbecause it reads like the SDK's logger.FSL-1.1-Apache-2.0, same as the CLI and the repo. Say so if this should be a more permissive license for a reusable library.0.1.0. The first npm publish happens when someone runs Release withcli-logger.via @BYK.
--
View Session in Sentry