From 1b8db12fde80270f72ab1a793edd6130dd97eb30 Mon Sep 17 00:00:00 2001 From: Jakob Schrettenbrunner Date: Sun, 10 Jan 2021 22:00:28 +0000 Subject: [PATCH] remote: only run debug logic when log level is debug --- remote/util.go | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/remote/util.go b/remote/util.go index 059bbe4..4cbc989 100644 --- a/remote/util.go +++ b/remote/util.go @@ -8,17 +8,18 @@ import ( // Logs the request into the debug log with all of the important request bits. // The authorization key will be cleaned up before being output. -// -// TODO(schrej): Somehow only execute the logic when log level is debug. func debugLogRequest(req *http.Request) { + if l, ok := log.Log.(*log.Logger); ok && l.Level != log.DebugLevel { + return + } headers := make(map[string][]string) for k, v := range req.Header { - if k != "Authorization" || len(v) == 0 { + if k != "Authorization" || len(v) == 0 || len(v[0]) == 0 { headers[k] = v continue } - headers[k] = []string{v[0][0:15] + "(redacted)"} + headers[k] = []string{"(redacted)"} } log.WithFields(log.Fields{