From 4c0ce35b698ba04f9a2c1ca74d74fe06580cb421 Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Tue, 30 Apr 2019 20:24:47 +0200 Subject: [PATCH] Improve internal kubernetes error logging 1. Remove duplicated timestamp keyval 2. Print full path to kubernetes file emitting the error --- cmd/fluxd/main.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/fluxd/main.go b/cmd/fluxd/main.go index 8ea9098b8..999601d39 100644 --- a/cmd/fluxd/main.go +++ b/cmd/fluxd/main.go @@ -8,6 +8,7 @@ import ( "os" "os/exec" "os/signal" + "runtime" "strconv" "strings" "sync" @@ -194,8 +195,11 @@ func main() { // Silence access errors logged internally by client-go k8slog := log.With(logger, "type", "internal kubernetes error", - "ts", log.DefaultTimestampUTC, - "caller", log.Caller(5)) // we want to log one level deeper than k8sruntime.HandleError + "kubernetes_caller", log.Valuer(func() interface{} { + _, file, line, _ := runtime.Caller(5) // we want to log one level deeper than k8sruntime.HandleError + idx := strings.Index(file, "/vendor/") + return file[idx+1:] + ":" + strconv.Itoa(line) + })) logErrorUnlessAccessRelated := func(err error) { errLower := strings.ToLower(err.Error()) if k8serrors.IsForbidden(err) || k8serrors.IsNotFound(err) ||