remote: only run debug logic when log level is debug

This commit is contained in:
Jakob Schrettenbrunner 2021-01-10 22:00:28 +00:00
parent 0414dbed8f
commit 1b8db12fde

View File

@ -8,17 +8,18 @@ import (
// Logs the request into the debug log with all of the important request bits. // Logs the request into the debug log with all of the important request bits.
// The authorization key will be cleaned up before being output. // 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) { func debugLogRequest(req *http.Request) {
if l, ok := log.Log.(*log.Logger); ok && l.Level != log.DebugLevel {
return
}
headers := make(map[string][]string) headers := make(map[string][]string)
for k, v := range req.Header { 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 headers[k] = v
continue continue
} }
headers[k] = []string{v[0][0:15] + "(redacted)"} headers[k] = []string{"(redacted)"}
} }
log.WithFields(log.Fields{ log.WithFields(log.Fields{