feat(logger): add global --log-format json option#2372
Merged
Conversation
Introduce a hidden, inherited `--log-format` (text|json, env DD_LOG_FORMAT) option on BaseCommand backed by a shared `this.logger` getter, so any command can emit JSONL logs with the level preserved (see #1991) without redeclaring the option or instantiating its own logger. - BaseCommand exposes a lazy `logger` getter (the single sanctioned stream sink) wired to the resolved log format; input validated via typanion `t.isEnum`, resolution order handled by clipanion's `{env}`. - Migrate the commands that declared their own Logger onto the inherited getter (forced by the type-level collision with the new getter). - ESLint: forbid direct this.context.stdout/stderr and process.stdout/stderr, scoped to a migrated-files allowlist that grows per PR. - createMockContext defaults `env` to a defined empty object so clipanion's `{env}` option does not crash on undefined. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Track the multi-PR migration to JSONL logging with a checklist; PR 1 (foundation) is complete. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The entrypoint printed the `datadog-ci v…` banner directly to stdout before the command ran, producing a non-JSON line that broke JSONL parsing. Parse argv first (`cli.process`), then emit the banner via the resolved command's logger (falling back to a default text logger for builtins / parse errors), so it becomes a JSON line under `--log-format json` and stays dim text otherwise. - Logger: add `isJsonOutput()` accessor. - BaseCommand: expose `logger` publicly so the entrypoint can reuse it. - printVersion now takes a Logger. Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
This comment has been minimized.
This comment has been minimized.
--log-format json option
Drarig29
marked this pull request as ready for review
June 22, 2026 08:18
rpelliard
approved these changes
Jun 22, 2026
anshuman-dd
approved these changes
Jun 22, 2026
hongkai
approved these changes
Jun 22, 2026
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.
What and why?
First step toward structured (JSONL) logging across the whole CLI, addressing #1991 (distinguish info/warn/error in machine-readable output).
Adds a single global
--log-formatoption (textdefault |json, envDD_LOG_FORMAT) that every command inherits without redeclaring it. Injsonmode, logs are emitted one JSON object per line with thelevelpreserved, so log pipelines no longer see every line asinfo.This is the foundation PR; per-plugin migrations and the synthetics reporter follow in later PRs (see
plans/json-logging-migration.md). The flag is hidden until coverage is broad enough.How?
BaseCommandexposes the inherited--log-formatoption (validated with typaniont.isEnum, env/precedence handled by clipanion's{env}) and a lazy, centralizedthis.loggergetter — the single sanctioned sink that writes to the stream.Loggeronto the inherited getter (forced by the type-level collision with the new getter).this.context.stdout/stderrandprocess.stdout/stderr, scoped to an allowlist that grows as commands migrate.createMockContextdefaultsenvto a defined empty object so clipanion's{env}option never readsundefined.datadog-ci vX.Y.Zbanner now flows through the resolved command's logger, so it becomes a JSON line under--log-format json(and is skipped for--help/version); stdout stays pure JSONL.plans/json-logging-migration.mdtracking the multi-PR rollout.Review checklist