aboutsummaryrefslogtreecommitdiffstats
path: root/client/go/internal/admin/vespa-wrapper/logfmt/showflags.go
blob: b69860e0312b1d7878562701b66de322d6225383 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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)
}