mirror of
https://github.com/caddyserver/caddy.git
synced 2026-01-17 01:30:34 +00:00
core: custom slog handlers for modules (log contextual data) (#7346)
This commit is contained in:
@@ -793,8 +793,10 @@ func (s *Server) logRequest(
|
||||
accLog *zap.Logger, r *http.Request, wrec ResponseRecorder, duration *time.Duration,
|
||||
repl *caddy.Replacer, bodyReader *lengthReader, shouldLogCredentials bool,
|
||||
) {
|
||||
ctx := r.Context()
|
||||
|
||||
// this request may be flagged as omitted from the logs
|
||||
if skip, ok := GetVar(r.Context(), LogSkipVar).(bool); ok && skip {
|
||||
if skip, ok := GetVar(ctx, LogSkipVar).(bool); ok && skip {
|
||||
return
|
||||
}
|
||||
|
||||
@@ -812,7 +814,7 @@ func (s *Server) logRequest(
|
||||
}
|
||||
|
||||
message := "handled request"
|
||||
if nop, ok := GetVar(r.Context(), "unhandled").(bool); ok && nop {
|
||||
if nop, ok := GetVar(ctx, "unhandled").(bool); ok && nop {
|
||||
message = "NOP"
|
||||
}
|
||||
|
||||
@@ -836,7 +838,7 @@ func (s *Server) logRequest(
|
||||
reqBodyLength = bodyReader.Length
|
||||
}
|
||||
|
||||
extra := r.Context().Value(ExtraLogFieldsCtxKey).(*ExtraLogFields)
|
||||
extra := ctx.Value(ExtraLogFieldsCtxKey).(*ExtraLogFields)
|
||||
|
||||
fieldCount := 6
|
||||
fields = make([]zapcore.Field, 0, fieldCount+len(extra.fields))
|
||||
|
||||
Reference in New Issue
Block a user