From 5cdc433603d0e391fa9d7e36565e0fa64d6581c6 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 28 Dec 2023 14:44:10 +0100 Subject: [PATCH] Set GIN to only log above level 400 (#1271) --- cmd/tumlive/tumlive.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/cmd/tumlive/tumlive.go b/cmd/tumlive/tumlive.go index 645ffa167..5b326a018 100755 --- a/cmd/tumlive/tumlive.go +++ b/cmd/tumlive/tumlive.go @@ -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()))