Skip to content

Commit

Permalink
Set GIN to only log above level 400
Browse files Browse the repository at this point in the history
  • Loading branch information
SebiWrn committed Dec 19, 2023
1 parent 7e37435 commit 0744b6c
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 @@ -58,13 +58,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 0744b6c

Please sign in to comment.