diff options
author | Arne Juul <arnej@yahooinc.com> | 2023-01-31 13:42:29 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahooinc.com> | 2023-01-31 14:30:39 +0000 |
commit | 1cf70cdb76ce8f66a8006963ab3dc1033fc342ec (patch) | |
tree | 3f23c12250277db86531ee09b88fea3fdddfd30c /client/go/script-utils/logfmt/showflags.go | |
parent | 3e54969fc961ee51c93404a37d559ab7ea2f9fe6 (diff) |
move vespa-logfmt command
Diffstat (limited to 'client/go/script-utils/logfmt/showflags.go')
-rw-r--r-- | client/go/script-utils/logfmt/showflags.go | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/client/go/script-utils/logfmt/showflags.go b/client/go/script-utils/logfmt/showflags.go new file mode 100644 index 00000000000..b69860e0312 --- /dev/null +++ b/client/go/script-utils/logfmt/showflags.go @@ -0,0 +1,76 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +// vespa logfmt command +// Author: arnej + +package logfmt + +import ( + "strings" +) + +// handle CLI flags for which fields to show when formatting a line + +type flagValueForShow struct { + shown map[string]bool + changed bool +} + +func defaultShowFlags() map[string]bool { + return map[string]bool{ + "time": true, + "fmttime": true, + "msecs": true, + "usecs": false, + "host": false, + "level": true, + "pid": false, + "service": true, + "component": true, + "message": true, + } +} + +func (v *flagValueForShow) Type() string { + return "show flags" +} + +func (v *flagValueForShow) String() string { + var buf strings.Builder + flagNames := []string{ + "time", + "fmttime", + "msecs", + "usecs", + "host", + "level", + "pid", + "service", + "component", + "message", + } + for _, flag := range flagNames { + if v.shown[flag] { + buf.WriteString(" +") + } else { + buf.WriteString(" -") + } + buf.WriteString(flag) + } + return buf.String() +} + +func (v *flagValueForShow) flags() map[string]bool { + return v.shown +} + +func (v *flagValueForShow) name() string { + return "show" +} + +func (v *flagValueForShow) unchanged() bool { + return !v.changed +} + +func (v *flagValueForShow) Set(val string) error { + return applyPlusMinus(val, v) +} |