aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/cmd/logfmt/regexflag.go
diff options
context:
space:
mode:
authorArne Juul <arnej@yahooinc.com>2022-07-25 13:21:50 +0000
committerArne Juul <arnej@yahooinc.com>2022-08-09 08:23:15 +0000
commit8e5c5def940890425d8a93e8afcad0980a0571d9 (patch)
treeda297891365817c35c51eb1d4411c5cc9a24ffcb /client/go/cmd/logfmt/regexflag.go
parent9dd6112864140a346ad1c1de0522656365deb7c0 (diff)
add logfmt code
* our own "tail -f" implementation in tail.go * filtering and formatting on per-line basis in handleline.go * recognition of vespa-internal components in internal.go * cobra-compatible flags for "level" in levelflags.go * cobra-compatible flags for "show" in showflags.go * cobra-compatible flag for regex handling in regexflag.go * options designed for compatibility with perl version in options.go * entrypoint in runlogfmt.go
Diffstat (limited to 'client/go/cmd/logfmt/regexflag.go')
-rw-r--r--client/go/cmd/logfmt/regexflag.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/client/go/cmd/logfmt/regexflag.go b/client/go/cmd/logfmt/regexflag.go
new file mode 100644
index 00000000000..8f7d2a91373
--- /dev/null
+++ b/client/go/cmd/logfmt/regexflag.go
@@ -0,0 +1,38 @@
+// 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 (
+ "regexp"
+)
+
+// optional regular expression filter, as a CLI flag
+
+type regexFlag struct {
+ regex *regexp.Regexp
+}
+
+func (re regexFlag) unmatched(s string) bool {
+ if re.regex == nil {
+ return false
+ }
+ return re.regex.FindStringIndex(s) == nil
+}
+
+func (v *regexFlag) Type() string {
+ return "regular expression"
+}
+
+func (v *regexFlag) String() string {
+ if v.regex == nil {
+ return "<none>"
+ }
+ return v.regex.String()
+}
+
+func (v *regexFlag) Set(val string) (r error) {
+ v.regex, r = regexp.Compile(val)
+ return
+}