Skip to content

Commit

Permalink
fix(server): Fix logger middleware log fields
Browse files Browse the repository at this point in the history
  • Loading branch information
MuXiu1997 committed Jan 27, 2023
1 parent 5fec9a9 commit 3ccd7e3
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions internal/app/traefik-github-oauth-server/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ func NewLoggerMiddleware(logger *zerolog.Logger) gin.HandlerFunc {
c.Next()

// Stop timer
timeStamp := time.Now()
latency := timeStamp.Sub(start)
end := time.Now()

clientIP := c.ClientIP()
method := c.Request.Method
Expand All @@ -54,13 +53,17 @@ func NewLoggerMiddleware(logger *zerolog.Logger) gin.HandlerFunc {

logger.Debug().
Str("module", "gin").
Time(zerolog.TimestampFieldName, timeStamp).
Time("time_start", start).
Int("status", statusCode).
Dur("latency", latency).
TimeDiff("took", end, start).
Str("client_ip", clientIP).
Str("method", method).
Str("path", path).
Str("error", errorMessage).
Func(func(e *zerolog.Event) {
if errorMessage != "" {
e.Str("error", errorMessage)
}
}).
Msg("")
}
}

0 comments on commit 3ccd7e3

Please sign in to comment.