Add --log level and keep diagnostics off stdout#346
Merged
Conversation
Closed
There was a problem hiding this comment.
Pull request overview
This PR separates client diagnostics from command output so machine-readable formats (JSON/YAML) and piping remain clean, while adding configurable diagnostic verbosity and improving human-facing terminal output (color/markers) plus graceful Ctrl-C handling.
Changes:
- Introduces a
--logflag and a customsloghandler that writes diagnostics to stderr and (by default) summarizes warnings at the end of the run. - Updates formatters and RPC flow to keep stdout reserved for command output, with structured file-transfer and error/status rendering.
- Adds shared style constants (ANSI colors + markers) and TTY detection to gate color automatically.
Reviewed changes
Copilot reviewed 15 out of 15 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
internal/style/style.go |
Adds shared ANSI + marker vocabulary and a single Colorize helper. |
internal/output/text.go |
Adds colorized markers for context/success/errors and introduces file-transfer rendering + humanBytes. |
internal/output/text_test.go |
Updates expectations for markers/colors and adds tests for error + file-transfer output. |
internal/output/output.go |
Adds TypeFileTransfer and FileTransfer payload type. |
internal/output/oneline.go |
Adds FileTransfer formatting for oneline output. |
internal/output/json.go |
Replaces log.Printf with slog.Warn for marshal failures (stderr diagnostics). |
internal/output/yaml.go |
Replaces log.Printf with slog.Warn for marshal failures (stderr diagnostics). |
CONTRIBUTING.md |
Documents stdout vs stderr rules and the new logging model/constraints. |
cmds/dutctl/term.go |
Adds TTY detection helper to gate color output. |
cmds/dutctl/term_test.go |
Tests TTY detection behavior for non-file writers and regular files. |
cmds/dutctl/rpc.go |
Uses slog, emits file-transfer events via formatter, and handles Ctrl-C via signal-cancelled context. |
cmds/dutctl/dutctl.go |
Adds --log flag, installs default slog handler, gates formatter color on TTY, and flushes diagnostics on exit. |
cmds/dutctl/clilog.go |
Implements --log parsing and a CLI-oriented slog.Handler with warn buffering + flush. |
cmds/dutctl/clilog_test.go |
Tests log mode parsing and handler behavior across warn/debug/none. |
.golangci.yml |
Enforces no direct stdout printing and restricts allowed slog entry points. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The client used to print diagnostic logs and errors to stdout, mixing them into command output and breaking the json/yaml formats. That is fixed, and how much the client reports is now configurable. - New --log flag sets diagnostic verbosity: debug, warn (default), or none. - Diagnostics and errors now go to stderr; stdout carries only command output, so piping and -f json|yaml stay clean. - At the default warn level, warnings are collected into a short summary at the end of the run rather than interrupting output. - Terminal output is color-coded (errors, warnings, file transfers, status); color turns off automatically when output is piped or redirected, or with -no-color. - Ctrl-C now stops a running command cleanly. The -v flag is unchanged. Signed-off-by: Jens Topp <jens.topp@blindspot.software>
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.
The client used to print diagnostic logs and errors to stdout, mixing them into command output and breaking the json/yaml formats. That is fixed, and how much the client reports is now configurable.
The -v flag is unchanged.