Skip to content

Commit

Permalink
logging: Prep for common_log removal (#4149)
Browse files Browse the repository at this point in the history
  • Loading branch information
francislavoie committed Jul 14, 2021
1 parent 1c6c771 commit 124ba1b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions modules/caddyhttp/server.go
Expand Up @@ -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()),
Expand Down
2 changes: 2 additions & 0 deletions modules/logging/encoders.go
Expand Up @@ -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))
Expand Down

0 comments on commit 124ba1b

Please sign in to comment.