From 66d42d553315fd26a3bbd677036ec211e2b49d86 Mon Sep 17 00:00:00 2001 From: xhe Date: Thu, 8 Jun 2023 10:39:33 +0800 Subject: [PATCH] api: change loglevel (#306) --- pkg/server/api/http.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/server/api/http.go b/pkg/server/api/http.go index ef8f384f..ec33c4ca 100644 --- a/pkg/server/api/http.go +++ b/pkg/server/api/http.go @@ -115,9 +115,6 @@ func (h *HTTPServer) rateLimit(c *gin.Context) { func (h *HTTPServer) attachLogger(c *gin.Context) { path := c.Request.URL.Path - if strings.HasPrefix(path, "/api/debug/health") { - return - } fields := make([]zapcore.Field, 0, 9) @@ -148,7 +145,13 @@ func (h *HTTPServer) attachLogger(c *gin.Context) { fields = append(fields, zap.Errors("errs", errs)) } - h.lg.Info(path, fields...) + if len(c.Errors) > 0 { + h.lg.Warn(path, fields...) + } else if strings.HasPrefix(path, "/api/debug") || strings.HasPrefix(path, "/api/metrics") { + h.lg.Debug(path, fields...) + } else { + h.lg.Info(path, fields...) + } } func (h *HTTPServer) readyState(c *gin.Context) {