Skip to content

Conversation

@abtreece
Copy link
Owner

@abtreece abtreece commented Jan 7, 2026

Summary

  • Add --log-format flag to switch between text and JSON log output
  • Leverages existing logrus JSONFormatter for structured logging
  • Makes log entries easier to parse by log indexing solutions (ELK, Splunk, etc.)

Changes

  • Added SetFormat() function to pkg/log/log.go
  • Added --log-format flag and log-format config option to cmd/confd/config.go
  • Updated documentation in docs/command-line-flags.md and docs/configuration-guide.md

Usage

Command line:

confd -backend=env -log-format=json -onetime

Config file (confd.toml):

log-format = "json"

Example Output

Text format (default):

2026-01-07T01:30:00Z hostname confd[1234]: INFO Backend set to env

JSON format:

{"level":"info","msg":"Backend set to env","time":"2026-01-07T01:30:00Z"}

Test plan

  • All existing tests pass
  • Build succeeds
  • -help shows new flag
  • Manual testing with -log-format=json

Closes #177

🤖 Generated with Claude Code

Add a --log-format flag to switch between text and JSON log output.
This leverages the existing logrus JSONFormatter for structured logging,
making log entries easier to parse by log indexing solutions.

Usage:
  confd -log-format=json ...

Or in confd.toml:
  log-format = "json"

Closes #177

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

❌ Patch coverage is 9.09091% with 10 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.36%. Comparing base (ab7a2d5) to head (30ef66a).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/log/log.go 0.00% 8 Missing ⚠️
cmd/confd/config.go 33.33% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #327      +/-   ##
==========================================
- Coverage   48.55%   48.36%   -0.19%     
==========================================
  Files          19       19              
  Lines        1761     1772      +11     
==========================================
+ Hits          855      857       +2     
- Misses        825      834       +9     
  Partials       81       81              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@abtreece abtreece merged commit 22b5eb1 into main Jan 7, 2026
8 checks passed
@abtreece abtreece deleted the feat/json-logs-support branch January 7, 2026 01:32
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.

Feature: Add JSON logs support

1 participant