From 681dc550e744c79f5208fb81ac484de4ce73b390 Mon Sep 17 00:00:00 2001 From: Dan Walsh Date: Thu, 26 Nov 2015 07:10:38 -0500 Subject: [PATCH 1/2] The loggingMiddleware function is adding lots of messages to the log When tools like kubernetes and cockpit are talking to the docker daemon actively, we are seeing large number of log messages that look like debug information. For example docker info adds the following line to journald. Nov 26 07:09:23 dhcp-10-19-62-196.boston.devel.redhat.com docker[32686]: time="2015-11-26T07:09:23.124503455-05:00" level=info msg="GET /v1.22/info" We think this should be Debug level not Info level. Signed-off-by: Dan Walsh Upstream-commit: cf4fb150880ec5f4153c291e67238e28f3cbdf9b Component: engine --- components/engine/api/server/middleware.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/engine/api/server/middleware.go b/components/engine/api/server/middleware.go index 628d0a3bef..f49cb55b79 100644 --- a/components/engine/api/server/middleware.go +++ b/components/engine/api/server/middleware.go @@ -25,7 +25,7 @@ type middleware func(handler httputils.APIFunc) httputils.APIFunc func (s *Server) loggingMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { if s.cfg.Logging { - logrus.Infof("%s %s", r.Method, r.RequestURI) + logrus.Debugf("%s %s", r.Method, r.RequestURI) } return handler(ctx, w, r, vars) } From d583bad1ef693f1120630bcbb324137827751c51 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Tue, 1 Dec 2015 14:33:33 -0500 Subject: [PATCH 2/2] Unify both debug logging middlewares. We can remove one function from the stack by injecting the middleware only when logging in enabled and the level is debug. Signed-off-by: David Calavera Upstream-commit: 82323294db96e8043244027c262481af6c8f478d Component: engine --- components/engine/api/server/middleware.go | 27 ++++++---------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/components/engine/api/server/middleware.go b/components/engine/api/server/middleware.go index f49cb55b79..f3e626f813 100644 --- a/components/engine/api/server/middleware.go +++ b/components/engine/api/server/middleware.go @@ -21,23 +21,12 @@ import ( // Any function that has the appropriate signature can be register as a middleware. type middleware func(handler httputils.APIFunc) httputils.APIFunc -// loggingMiddleware logs each request when logging is enabled. -func (s *Server) loggingMiddleware(handler httputils.APIFunc) httputils.APIFunc { - return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if s.cfg.Logging { - logrus.Debugf("%s %s", r.Method, r.RequestURI) - } - return handler(ctx, w, r, vars) - } -} - // debugRequestMiddleware dumps the request to logger -// This is implemented separately from `loggingMiddleware` so that we don't have to -// check the logging level or have httputil.DumpRequest called on each request. -// Instead the middleware is only injected when the logging level is set to debug -func (s *Server) debugRequestMiddleware(handler httputils.APIFunc) httputils.APIFunc { +func debugRequestMiddleware(handler httputils.APIFunc) httputils.APIFunc { return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { - if s.cfg.Logging && r.Method == "POST" { + logrus.Debugf("%s %s", r.Method, r.RequestURI) + + if r.Method == "POST" { if err := httputils.CheckForJSON(r); err == nil { var buf bytes.Buffer if _, err := buf.ReadFrom(r.Body); err == nil { @@ -53,6 +42,7 @@ func (s *Server) debugRequestMiddleware(handler httputils.APIFunc) httputils.API } } } + return handler(ctx, w, r, vars) } } @@ -136,14 +126,11 @@ func (s *Server) handleWithGlobalMiddlewares(handler httputils.APIFunc) httputil versionMiddleware, s.corsMiddleware, s.userAgentMiddleware, - s.loggingMiddleware, } // Only want this on debug level - // this is separate from the logging middleware so that we can do this check here once, - // rather than for each request. - if logrus.GetLevel() == logrus.DebugLevel { - middlewares = append(middlewares, s.debugRequestMiddleware) + if s.cfg.Logging && logrus.GetLevel() == logrus.DebugLevel { + middlewares = append(middlewares, debugRequestMiddleware) } h := handler