feat: custom slog handlers for modules (log contextual data)#7346
feat: custom slog handlers for modules (log contextual data)#7346mholt merged 1 commit intocaddyserver:masterfrom
Conversation
6c5c95c to
9ce4728
Compare
9ce4728 to
a62d829
Compare
mholt
left a comment
There was a problem hiding this comment.
Thanks Kevin!
Just so I understand, this doesn't affect MOST of Caddy's logs, i.e. won't noticeably impact their performance or change them -- just the logs that are emitted without zap, right?
| type slogHandlerFactory func(handler slog.Handler, core zapcore.Core, moduleID string) slog.Handler | ||
|
|
||
| var ( | ||
| slogHandlerFactories []slogHandlerFactory | ||
| slogHandlerFactoriesMu sync.RWMutex | ||
| ) |
There was a problem hiding this comment.
I know this is an annoying request, but how would you feel if we drop the "factory" thing? 😆 I just... it feels like Java.
What about like slogHandlerWrapper instead? Or, maybe even just slogHandler? I am not 100% sure since I haven't dived into slog too much yet to be that familiar with it.
There was a problem hiding this comment.
Actually, this is a list of factory to create log/slog.Handler instances when needed (these are "wrapping" the main instance by implementing the decorator pattern). Removing the factory suffix will be confusing IMHO.
|
Right. |
mholt
left a comment
There was a problem hiding this comment.
Alrighty -- sounds good then. Thank you!
With this patch, contextual data can be added to all logs generated by a logger retrieved using
context.Slogger().For instance, this allows FrankenPHP and Mercure to include OpenTelemetry's traceID and spanID to all logs they generate using the logger created by Caddy.
Modules can also register handlers to add contextual data of their own (like the Mercure update ID, for instance).
Assistance Disclosure
No AI was used.