Francis Lavoie 4 years ago
committed by GitHub
parent
commit
124ba1ba71
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      modules/caddyhttp/server.go
  2. 2
      modules/logging/encoders.go

3
modules/caddyhttp/server.go

@ -184,8 +184,11 @@ func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
log = logger.Error log = logger.Error
} }
userID, _ := repl.GetString("http.auth.user.id")
log("handled request", log("handled request",
zap.String("common_log", repl.ReplaceAll(commonLogFormat, commonLogEmptyValue)), zap.String("common_log", repl.ReplaceAll(commonLogFormat, commonLogEmptyValue)),
zap.String("user_id", userID),
zap.Duration("duration", duration), zap.Duration("duration", duration),
zap.Int("size", wrec.Size()), zap.Int("size", wrec.Size()),
zap.Int("status", wrec.Status()), zap.Int("status", wrec.Status()),

2
modules/logging/encoders.go

@ -307,6 +307,8 @@ func (lec *LogEncoderConfig) ZapcoreEncoderConfig() zapcore.EncoderConfig {
timeFormat = "2006/01/02 15:04:05.000" timeFormat = "2006/01/02 15:04:05.000"
case "wall_nano": case "wall_nano":
timeFormat = "2006/01/02 15:04:05.000000000" 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) { timeFormatter = func(ts time.Time, encoder zapcore.PrimitiveArrayEncoder) {
encoder.AppendString(ts.UTC().Format(timeFormat)) encoder.AppendString(ts.UTC().Format(timeFormat))

Loading…
Cancel
Save