Skip to content

Fix | Emit JSON logs when --log-format is json - #496

Merged
dag-andersen merged 1 commit into
dag-andersen:mainfrom
choppedpork:fix/json-log-format
Oct 7, 2026
Merged

dag-andersen merged 1 commit into
dag-andersen:mainfrom
choppedpork:fix/json-log-format

Conversation

@choppedpork

Copy link
Copy Markdown
Contributor

One more small fix 🙂

--log-format json currently has no effect: every format goes through zerolog's ConsoleWriter, which converts log events into human-readable text, so json produces plain text lines rather than one JSON object per line. This PR makes json write zerolog's native JSON with a timestamp, in both normal and --debug mode. human
output is unchanged.

When the flag was added in d925b0a it worked, because the ConsoleWriter was only set up for human and json kept zerolog's default JSON logger. caf6a05 then moved the debug and human settings onto a shared consoleWriter and assigned log.Logger = log.Output(consoleWriter) unconditionally, so json has gone through the
console writer ever since.

That's why the diff is bigger than the bug: json needs its own logger rather than a differently configured ConsoleWriter. Logger construction now lives in newLogger, which takes an io.Writer so both formats can be tested against a buffer.

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

@dag-andersen dag-andersen left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Wow, that bug has been around for a long time! clearly no one is using that feature haha - Great work!

@dag-andersen
dag-andersen merged commit 9214629 into dag-andersen:main Oct 7, 2026
3 checks passed
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.

2 participants