summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorFrancis Lavoie <lavofr@gmail.com>2021-07-14 13:07:38 -0400
committerGitHub <noreply@github.com>2021-07-14 11:07:38 -0600
commit124ba1ba714220322c65625012c564f89b75bfc9 (patch)
tree3ad8d07414fd5b9a7d507d9b0e3a5fb645dbbf0c /modules
parent1c6c7714a38879f78c486fcb9c7c6e39fc39c6a5 (diff)
logging: Prep for `common_log` removal (#4149)
See https://github.com/caddyserver/caddy/issues/4148#issuecomment-833207811
Diffstat (limited to 'modules')
-rw-r--r--modules/caddyhttp/server.go3
-rw-r--r--modules/logging/encoders.go2
2 files changed, 5 insertions, 0 deletions
diff --git a/modules/caddyhttp/server.go b/modules/caddyhttp/server.go
index 9dc1028..8094832 100644
--- a/modules/caddyhttp/server.go
+++ b/modules/caddyhttp/server.go
@@ -184,8 +184,11 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log = logger.Error
}
+ userID, _ := repl.GetString("http.auth.user.id")
+
log("handled request",
zap.String("common_log", repl.ReplaceAll(commonLogFormat, commonLogEmptyValue)),
+ zap.String("user_id", userID),
zap.Duration("duration", duration),
zap.Int("size", wrec.Size()),
zap.Int("status", wrec.Status()),
diff --git a/modules/logging/encoders.go b/modules/logging/encoders.go
index 40e86bd..8b2b44c 100644
--- a/modules/logging/encoders.go
+++ b/modules/logging/encoders.go
@@ -307,6 +307,8 @@ func (lec *LogEncoderConfig) ZapcoreEncoderConfig() zapcore.EncoderConfig {
timeFormat = "2006/01/02 15:04:05.000"
case "wall_nano":
timeFormat = "2006/01/02 15:04:05.000000000"
+ case "common_log":
+ timeFormat = "02/Jan/2006:15:04:05 -0700"
}
timeFormatter = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
encoder.AppendString(ts.UTC().Format(timeFormat))