logging: Buffer the logs before config is loaded#7245
Merged
francislavoie merged 2 commits intomasterfrom Sep 10, 2025
Merged
Conversation
mholt
approved these changes
Sep 10, 2025
Member
mholt
left a comment
There was a problem hiding this comment.
Oh neat, this is a clever solution. Thanks for working on this. You're spoiling our user base with niceties. 😉
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #7209 and probably multiple other issues we've had in the past.
My idea to solve this was:
caddy run, set up a temporary in-memory log buffer and capture all logs into thatcaddy runfails at any point before config is loaded, flush the buffer directly to the default logger (stderr, effectively)To test this, I used this config:
{ admin localhost:2020 log { output file ./test.log level info format console { level_format upper } } } :2021 { respond "Hello, Caddy!" }Then simply running
caddy runon that Caddyfile, seeing that all logs end up intest.log.If I make a change like removing a
{to produce a config error, I see this in my terminal, as expected:Assistance Disclosure
I used RooCode + GPT-4.1 to ideate, and it produced the
logbuffer.goimplementation, I wrote the remainder.