Skip to content

Commit

Permalink
Set GIN to only log above level 400 (TUM-Dev#1271)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebiWrn authored Dec 28, 2023
1 parent 2f203ba commit 5cdc433
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions cmd/tumlive/tumlive.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,16 @@ func GinServer() (err error) {
}

router.Use(gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
return fmt.Sprintf("{\"service\": \"GIN\", \"time\": %s, \"status\": %d, \"client\": \"%s\", \"path\": \"%s\", \"agent\": %s}\n",
param.TimeStamp.Format(time.DateTime),
param.StatusCode,
param.ClientIP,
param.Path,
param.Request.UserAgent(),
)
if param.StatusCode >= 400 {
return fmt.Sprintf("{\"service\": \"GIN\", \"time\": %s, \"status\": %d, \"client\": \"%s\", \"path\": \"%s\", \"agent\": %s}\n",
param.TimeStamp.Format(time.DateTime),
param.StatusCode,
param.ClientIP,
param.Path,
param.Request.UserAgent(),
)
}
return ""
}))

router.Use(tools.InitContext(dao.NewDaoWrapper()))
Expand Down

0 comments on commit 5cdc433

Please sign in to comment.