@marcel91200 / caddy Mirror · read-only / commits / 124ba1ba
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

logging: Prep for `common_log` removal (#4149)

See https://github.com/caddyserver/caddy/issues/4148#issuecomment-833207811

Francis Lavoie committed Jul 14, 2021 at 13:07 UTC 124ba1ba714220322c65625012c564f89b75bfc9
2 files changed +5
modules/caddyhttp/server.go
+3
@@ -184,8 +184,11 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
184 log = logger.Error
185 }
186
187 + userID, _ := repl.GetString("http.auth.user.id")
188 +
189 log("handled request",
190 zap.String("common_log", repl.ReplaceAll(commonLogFormat, commonLogEmptyValue)),
191 + zap.String("user_id", userID),
192 zap.Duration("duration", duration),
193 zap.Int("size", wrec.Size()),
194 zap.Int("status", wrec.Status()),
modules/logging/encoders.go
+2
@@ -307,6 +307,8 @@ func (lec *LogEncoderConfig) ZapcoreEncoderConfig() zapcore.EncoderConfig {
307 timeFormat = "2006/01/02 15:04:05.000"
308 case "wall_nano":
309 timeFormat = "2006/01/02 15:04:05.000000000"
310 + case "common_log":
311 + timeFormat = "02/Jan/2006:15:04:05 -0700"
312 }
313 timeFormatter = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
314 encoder.AppendString(ts.UTC().Format(timeFormat))