Skip to content

Add --log level and keep diagnostics off stdout#346

Merged
jenstopp merged 1 commit into
mainfrom
client-logging
Jun 29, 2026
Merged

Add --log level and keep diagnostics off stdout#346
jenstopp merged 1 commit into
mainfrom
client-logging

Conversation

@jenstopp

Copy link
Copy Markdown
Member

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.

@jenstopp jenstopp requested a review from Copilot June 29, 2026 10:17
@jenstopp jenstopp linked an issue Jun 29, 2026 that may be closed by this pull request

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 --log flag and a custom slog handler 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.

Comment thread cmds/dutctl/dutctl.go
Comment thread internal/output/oneline.go
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>
@jenstopp jenstopp merged commit 93df26a into main Jun 29, 2026
8 checks passed
@jenstopp jenstopp deleted the client-logging branch June 29, 2026 16:10
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.

Clean client side logs

2 participants