Skip to content

refactor(output): make slog silence a level rather than a convention - #133

Open
Ilyes512 wants to merge 1 commit into
fix/GH-115-validate-output-formatfrom
refactor/GH-114-setup-logger
Open

refactor(output): make slog silence a level rather than a convention#133
Ilyes512 wants to merge 1 commit into
fix/GH-115-validate-output-formatfrom
refactor/GH-114-setup-logger

Conversation

@Ilyes512

@Ilyes512 Ilyes512 commented Sep 2, 2026

Copy link
Copy Markdown
Member

Logger setup happened in two files and neither call was the whole story.
NewApp installed a text handler on os.Stderr at Info level; PersistentPreRunE
adjusted the level and replaced the handler only when both --debug and
-o json were given.

That left three problems. The documented "silent on a normal run" promise held
only because every log point in the tree happens to be slog.Debug — the first
slog.Info anyone reached for would print on every run. The far more common
--debug alone kept the os.Stderr handler, so debug output escaped the buffers
a test points the command at. And the format coupling lived as a nested
conditional in a command file rather than as a property of the logger.

output.SetupLogger is now the only place a handler is built, and LevelSilent —
above every level slog defines — is what a run without --debug gets. It is
called twice: once by NewApp with os.Stderr, since cobra has not parsed the
flags yet and a failure before that still needs a logger, and once by
PersistentPreRunE with the command's own stderr and the resolved flags.

The unused WithDebug / WithHandler / HandlerFactory option plumbing goes with
it; nothing outside its own doc comment ever called it.

template validate no longer forces the level to Debug. That line was
undocumented and untested, and made the one command spray diagnostics at a
user who had not asked for them — which is exactly the invariant above.

Closes #114


Stack created with GitHub Stacks CLIGive Feedback 💬

Logger setup happened in two files and neither call was the whole story.
NewApp installed a text handler on os.Stderr at Info level; PersistentPreRunE
adjusted the level and replaced the handler only when both --debug and
-o json were given.

That left three problems. The documented "silent on a normal run" promise held
only because every log point in the tree happens to be slog.Debug — the first
slog.Info anyone reached for would print on every run. The far more common
--debug alone kept the os.Stderr handler, so debug output escaped the buffers
a test points the command at. And the format coupling lived as a nested
conditional in a command file rather than as a property of the logger.

output.SetupLogger is now the only place a handler is built, and LevelSilent —
above every level slog defines — is what a run without --debug gets. It is
called twice: once by NewApp with os.Stderr, since cobra has not parsed the
flags yet and a failure before that still needs a logger, and once by
PersistentPreRunE with the command's own stderr and the resolved flags.

The unused WithDebug / WithHandler / HandlerFactory option plumbing goes with
it; nothing outside its own doc comment ever called it.

template validate no longer forces the level to Debug. That line was
undocumented and untested, and made the one command spray diagnostics at a
user who had not asked for them — which is exactly the invariant above.

Closes #114
@Ilyes512
Ilyes512 marked this pull request as ready for review September 2, 2026 22:20
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