-
-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
logging: Implement append
encoder, allow flatter filters config
#6069
Conversation
c5c1075
to
2e09727
Compare
I just added another commit which makes it possible to configure fields for both Before:
After:
|
8dfec60
to
ad08746
Compare
add
encoderadd
encoder, allow flatter filters config
ad08746
to
6970d20
Compare
Oh -- lol, would it be prudent to rename this to |
Okay 👍 |
6970d20
to
795d104
Compare
add
encoder, allow flatter filters configappend
encoder, allow flatter filters config
2d9a87f
to
1e0f2fa
Compare
GO_SEMVER: '~1.22.0' | ||
GO_SEMVER: '~1.22.1' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Feature requested by @yroc92
This adds a simple encoder called
append
which can append one or more log fields to all log entries that the logger processes.This is inspired (and largely copy-paste) of the
filter
encoder, and as such it wraps another encoder (defaulting tojson
orconsole
as per #5980).Since this module does not have access to the request context, it cannot use request placeholders, but it may use global placeholders such as the ones from https://caddyserver.com/docs/conventions#placeholders.
This is complementary to #6066 which allows appending extra log fields to access logs only, and allows appending data from the request context.
Most commonly, this will probably be used to append things like a Caddy instance ID, to identify which instance the log was produced from in some log ingress tool.
For example, in global options:
And running with
MACHINE=foo caddy run
, a log like this is shown:The key functionality of this encoder is in the
func (fe AppendEncoder) EncodeEntry
function (near the end of the file). The rest of the code is pretty much just zap boilerplate because we need to implement thezapcore.Encoder
interface which has a ton of functions 😬 we're just passing them through to the wrapped encoder.