From 4b4717fd4a286dabe42ba2278ede6ef6547f3e22 Mon Sep 17 00:00:00 2001 From: James Munson Date: Fri, 25 Oct 2024 15:05:16 -0600 Subject: [PATCH] fix(logging): only log GET requests at debug level Signed-off-by: James Munson (cherry picked from commit 58ec5385a3face64a038d041a7b92d5bec1f7d1b) --- app/daemon.go | 10 +--------- util/util.go | 6 ++---- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/app/daemon.go b/app/daemon.go index f17179b30b..f79bf24247 100644 --- a/app/daemon.go +++ b/app/daemon.go @@ -219,15 +219,7 @@ func startManager(c *cli.Context) error { server := api.NewServer(m, wsc) router := http.Handler(api.NewRouter(server)) - router = util.FilteredLoggingHandler(map[string]struct{}{ - "/v1/apiversions": {}, - "/v1/schemas": {}, - "/v1/settings": {}, - "/v1/volumes": {}, - "/v1/nodes": {}, - "/v1/engineimages": {}, - "/v1/events": {}, - }, os.Stdout, router) + router = util.FilteredLoggingHandler(os.Stdout, router) router = handlers.ProxyHeaders(router) listen := types.GetAPIServerAddressFromIP(currentIP) diff --git a/util/util.go b/util/util.go index 693ba7f8f9..411e02a012 100644 --- a/util/util.go +++ b/util/util.go @@ -456,15 +456,13 @@ func RunAsync(wg *sync.WaitGroup, f func()) { } type filteredLoggingHandler struct { - filteredPaths map[string]struct{} handler http.Handler loggingHandler http.Handler } -func FilteredLoggingHandler(filteredPaths map[string]struct{}, writer io.Writer, router http.Handler) http.Handler { +func FilteredLoggingHandler(writer io.Writer, router http.Handler) http.Handler { return filteredLoggingHandler{ - filteredPaths: filteredPaths, handler: router, loggingHandler: handlers.CombinedLoggingHandler(writer, router), } @@ -473,7 +471,7 @@ func FilteredLoggingHandler(filteredPaths map[string]struct{}, writer io.Writer, func (h filteredLoggingHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { switch req.Method { case "GET": - if _, exists := h.filteredPaths[req.URL.Path]; exists { + if logrus.GetLevel() < logrus.DebugLevel { h.handler.ServeHTTP(w, req) return }