Skip to content

fix(cli): keep dirctl logs off stdout - #2016

Merged
tkircsi merged 2 commits into
agntcy:mainfrom
dlanov:fix-2009-dirctl-log-stderr
Sep 9, 2026
Merged

tkircsi merged 2 commits into
agntcy:mainfrom
dlanov:fix-2009-dirctl-log-stderr

Conversation

@dlanov

@dlanov dlanov commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Fixes #2009.

Summary

Keep dirctl diagnostic logs off stdout so machine-readable command output can be safely piped or redirected.

  • Default normal dirctl logging to stderr.
  • Preserve stdout logging for dirctl daemon start, apiserver, and reconciler.
  • Add DIRECTORY_LOGGER_LOG_STREAM=stdout|stderr for explicit stream selection.
  • Keep DIRECTORY_LOGGER_LOG_FILE as the highest-priority logging destination.
  • Preserve already-created component loggers by routing the binary default through a switchable writer.

Behavior

With no explicit log stream:

  • normal dirctl commands log to stderr
  • dirctl daemon start continues logging to stdout
  • apiserver and reconciler remain unchanged on stdout

Explicit DIRECTORY_LOGGER_LOG_STREAM overrides the binary default, while a valid DIRECTORY_LOGGER_LOG_FILE overrides both.

This keeps JSON, JSONL, raw, and binary command results clean on stdout.

Testing

  • go test -race -count=10 ./logging/...
  • go test -race -count=1 ./cmd/... ./presenter/...
  • go build ./... for cli, server, and reconciler
  • go vet ./... for cli, server, reconciler, and utils/logging
  • git diff --check

Manual verification confirmed:

  • default dirctl: logs on stderr, stdout clean
  • LOG_STREAM=stdout: logs on stdout
  • LOG_STREAM=stderr: logs on stderr
  • LOG_FILE takes precedence over LOG_STREAM
  • dirctl daemon start retains stdout logging

@dlanov
dlanov requested a review from a team as a code owner August 12, 2026 16:47
@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Aug 12, 2026
@dlanov
dlanov force-pushed the fix-2009-dirctl-log-stderr branch from 6f549ca to db6d54d Compare August 12, 2026 17:07
@codecov

codecov Bot commented Aug 12, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 93.93939% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
utils/logging/logging.go 93.3% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@tkircsi tkircsi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM! Thank you for your contribution!

@tkircsi
tkircsi merged commit d9e488d into agntcy:main Sep 9, 2026
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 200-999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: dirctl writes structured logs to stdout, corrupting machine-readable command output

2 participants