Skip to content

fix: config warnings honor logging.format/level (#113)#119

Merged
skyoo2003 merged 1 commit into
mainfrom
fix/113-config-warnings-honor-logging
Jul 24, 2026
Merged

fix: config warnings honor logging.format/level (#113)#119
skyoo2003 merged 1 commit into
mainfrom
fix/113-config-warnings-honor-logging

Conversation

@skyoo2003

Copy link
Copy Markdown
Owner

Summary

Config-time log warnings emitted during config.parse() now honor the operator-configured logging.format/logging.level instead of always going out through the default text handler before logging was set up.

Related Issue

Fixes #113

Changes

  • Add cmd/devcloud/buffer.go: a buffering slog.Handler that captures records and replays them through a destination handler, gated by that handler's level filter (flushTo).
  • Wire it into cmd/devcloud/main.go: install the buffer as the default handler before config load, then replay buffered records through the real handler after setupLogging(). The load-error path falls back to the default handler and flushes so the error and any buffered warnings are still surfaced.
  • internal/config is left untouched — the fix is purely a startup-ordering change in main.
  • Add a Fixed changelog fragment.

Test Plan

  • New cmd/devcloud/buffer_test.go: buffered Info+Warn records flushed to a JSON handler at level=warn — asserts the Warn record (with structured attrs) is replayed as JSON and the Info record is dropped; a second flush is a no-op. Also asserts the buffer accepts all levels.
  • go vet ./cmd/devcloud/, go test ./cmd/devcloud/, go build ./... all pass.
  • golangci-lint run ./cmd/devcloud/ → 0 issues.
  • Manual end-to-end: DEVCLOUD_SERVICES=tier9 devcloud --config <yaml with logging.format=json, deprecated dashboard key> → both config warnings now emit as JSON with structured attrs ("token":"tier9").

Checklist

  • Self-reviewed the code
  • Added/updated tests
  • Lint/format passes (golangci-lint run)
  • Updated documentation (if applicable) — N/A
  • Added a Changie changelog fragment for user-facing changes (changie new, see docs/release.md)

parse() emitted deprecation and unknown-tier warnings through the default
text handler before setupLogging() installed the operator-configured one,
so they ignored logging.format/level and broke JSON log parsers.

Buffer log records during config load and replay them through the real
handler once it is installed, filtering by the configured level. Keeps the
config package untouched; startup ordering is fixed in main.

Fixes #113
@github-actions github-actions Bot added the tests Test code and test infrastructure label Jul 24, 2026
@skyoo2003 skyoo2003 self-assigned this Jul 24, 2026
@sourcery-ai

sourcery-ai Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Startup logging is refactored so config-time warnings are first buffered via a temporary slog.Handler and then replayed through the operator-configured logger, ensuring they honor logging.format/logging.level; tests validate buffering and flushing behavior, and a changelog fragment documents the fix.

File-Level Changes

Change Details Files
Introduce a buffering slog handler used during startup to capture pre-config logging output and later replay it through the real handler, honoring its format and level.
  • Implement bufferHandler that stores cloned slog.Record values and exposes Enabled, Handle, WithAttrs, WithGroup, and flushTo methods.
  • Ensure flushTo replays only records accepted by the destination handler’s level filter and then clears the buffer.
  • Document single-threaded assumptions in bufferHandler with a note about adding a mutex if startup logging becomes concurrent.
cmd/devcloud/buffer.go
Wire the buffer handler into the devcloud startup flow so config.parse() warnings are emitted through the configured logger or the default handler on failure.
  • Install bufferHandler as the default slog handler before config loading begins.
  • On config load failure, initialize logging with an empty LoggingConfig, flush buffered records to the resulting default handler, then log and exit on error.
  • On successful config load, call setupLogging with cfg.Logging and flush buffered records to the now-configured default handler.
cmd/devcloud/main.go
Add tests that verify buffered records respect the destination handler’s JSON formatting and level filtering when flushed.
  • Test that buffered Info and Warn records flushed to a JSON handler at level=warn result in only the Warn record being emitted as JSON with structured attributes, and that a second flush is a no-op.
  • Test that bufferHandler.Enabled returns true for debug level to confirm it buffers all levels without pre-filtering.
cmd/devcloud/buffer_test.go
Document the user-facing behavior change that config-time warnings now honor logging.format/logging.level. .changes/unreleased/Fixed-113.yaml

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot 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.

Hey - I've left some high level feedback:

  • The bufferHandler is explicitly single-threaded; if there’s any chance config-loading logs could be emitted from multiple goroutines in the future, consider adding a mutex now to avoid subtle data races around the records slice.
  • bufferHandler.WithAttrs and WithGroup intentionally no-op, which could be surprising if future config-time logging starts using structured logging; consider tracking attrs/groups so the behavior matches other handlers even during buffering.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The bufferHandler is explicitly single-threaded; if there’s any chance config-loading logs could be emitted from multiple goroutines in the future, consider adding a mutex now to avoid subtle data races around the records slice.
- bufferHandler.WithAttrs and WithGroup intentionally no-op, which could be surprising if future config-time logging starts using structured logging; consider tracking attrs/groups so the behavior matches other handlers even during buffering.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@skyoo2003
skyoo2003 merged commit 25068ee into main Jul 24, 2026
8 checks passed
@skyoo2003
skyoo2003 deleted the fix/113-config-warnings-honor-logging branch July 24, 2026 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

tests Test code and test infrastructure

Projects

None yet

Development

Successfully merging this pull request may close these issues.

config: warnings in parse() emit before logging is configured (ignores logging.format/level)

1 participant