From 37c21f9dde3b313d784e3ca6959e635a570611e6 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Wed, 25 Sep 2024 13:52:49 +0000 Subject: [PATCH] vespa-logfmt now shows all levels by default; also extend unit tests and fix a corner case --- .../admin/vespa-wrapper/logfmt/levelflags.go | 12 +++++++----- .../admin/vespa-wrapper/logfmt/levelflags_test.go | 13 +++++++------ .../admin/vespa-wrapper/logfmt/showflags.go | 4 +++- .../admin/vespa-wrapper/logfmt/showflags_test.go | 3 ++- 4 files changed, 19 insertions(+), 13 deletions(-) diff --git a/client/go/internal/admin/vespa-wrapper/logfmt/levelflags.go b/client/go/internal/admin/vespa-wrapper/logfmt/levelflags.go index ae786c24a2fb..b248491e530e 100644 --- a/client/go/internal/admin/vespa-wrapper/logfmt/levelflags.go +++ b/client/go/internal/admin/vespa-wrapper/logfmt/levelflags.go @@ -21,10 +21,10 @@ func defaultLevelFlags() map[string]bool { "error": true, "warning": true, "info": true, - "config": false, - "event": false, - "debug": false, - "spam": false, + "config": true, + "event": true, + "debug": true, + "spam": true, } } @@ -68,5 +68,7 @@ func (v *flagValueForLevel) unchanged() bool { } func (v *flagValueForLevel) Set(val string) error { - return applyPlusMinus(val, v) + err := applyPlusMinus(val, v) + v.changed = true + return err } diff --git a/client/go/internal/admin/vespa-wrapper/logfmt/levelflags_test.go b/client/go/internal/admin/vespa-wrapper/logfmt/levelflags_test.go index c933d481d305..9495c8be631a 100644 --- a/client/go/internal/admin/vespa-wrapper/logfmt/levelflags_test.go +++ b/client/go/internal/admin/vespa-wrapper/logfmt/levelflags_test.go @@ -37,18 +37,19 @@ func TestLevelFlags(t *testing.T) { t.Fail() } } - check(" +fatal +error +warning +info -config -event -debug -spam") + check(" +fatal +error +warning +info +config +event +debug +spam") check(" -fatal -error -warning -info -config -event -debug -spam", "-all") check(" +fatal +error +warning +info +config +event +debug +spam", "all") check(" +fatal +error +warning +info +config +event +debug +spam", "+all") check(" -fatal -error -warning -info -config -event +debug -spam", "debug") check(" +fatal +error +warning +info +config +event +debug -spam", "all-spam") check(" +fatal +error +warning +info +config +event +debug -spam", "all", "-spam") - check(" +fatal +error +warning -info -config +event -debug -spam", "+event", "-info") - check(" +fatal +error -warning -info -config +event -debug -spam", "+event,-info,-warning,config") - check(" +fatal +error -warning -info +config +event -debug -spam", "+event,-info,-warning,+config") - check(" +fatal +error -warning -info +config +event -debug -spam", "+event,-info", "-warning,+config") - check(" -fatal -error -warning -info +config -event -debug -spam", "+event", "-info", "-warning", "config") + check(" +fatal +error +warning -info +config +event +debug +spam", "+event", "-info") + check(" +fatal +error -warning -info -config +event +debug +spam", "+event,-info,-warning,config") + check(" +fatal +error -warning -info +config +event +debug +spam", "+event,-info,-warning,+config") + check(" +fatal +error -warning -info +config +event +debug +spam", "+event,-info", "-warning,+config") + check(" +fatal +error -warning -info +config +event +debug +spam", "+event", "-info", "-warning", "config") + check(" -fatal +error -warning +info -config -event +debug -spam", "info", "debug", "error") check = func(expectErr string, texts ...string) { var target flagValueForLevel target.levels = defaultLevelFlags() diff --git a/client/go/internal/admin/vespa-wrapper/logfmt/showflags.go b/client/go/internal/admin/vespa-wrapper/logfmt/showflags.go index 76cba6fa2dde..a60878aec925 100644 --- a/client/go/internal/admin/vespa-wrapper/logfmt/showflags.go +++ b/client/go/internal/admin/vespa-wrapper/logfmt/showflags.go @@ -72,5 +72,7 @@ func (v *flagValueForShow) unchanged() bool { } func (v *flagValueForShow) Set(val string) error { - return applyPlusMinus(val, v) + err := applyPlusMinus(val, v) + v.changed = true + return err } diff --git a/client/go/internal/admin/vespa-wrapper/logfmt/showflags_test.go b/client/go/internal/admin/vespa-wrapper/logfmt/showflags_test.go index b287ca677b47..53151cfb7113 100644 --- a/client/go/internal/admin/vespa-wrapper/logfmt/showflags_test.go +++ b/client/go/internal/admin/vespa-wrapper/logfmt/showflags_test.go @@ -37,7 +37,8 @@ func TestShowFlags(t *testing.T) { check(" +time -fmttime +msecs -usecs +host +level -pid -service +component +message", "+host,-fmttime,-service,pid") check(" +time -fmttime +msecs -usecs +host +level +pid -service +component +message", "+host,-fmttime,-service,+pid") check(" +time -fmttime +msecs -usecs +host +level +pid -service +component +message", "+host,-fmttime", "-service,+pid") - check(" -time -fmttime -msecs -usecs -host -level +pid -service -component -message", "+host", "-fmttime", "-service", "pid") + check(" +time -fmttime +msecs -usecs +host +level +pid -service +component +message", "+host", "-fmttime", "-service", "pid") + check(" -time -fmttime -msecs -usecs +host -level +pid -service +component -message", "host", "component", "pid") check = func(expectErr string, texts ...string) { var target flagValueForShow target.shown = defaultShowFlags()