-
Notifications
You must be signed in to change notification settings - Fork 0
/
flags.go
49 lines (42 loc) · 1.9 KB
/
flags.go
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
package logger
import (
"flag"
)
var (
format string
enab int
stdout bool
stderr bool
file File
klogV int
)
var (
commandLine flag.FlagSet
klogFS = &flag.FlagSet{}
)
func init() {
commandLine.BoolVar(&stdout, "logger-stdout", true, "Log to standard out")
commandLine.BoolVar(&stderr, "logger-stderr", false, "Log to standard error")
commandLine.StringVar(&format, "logger-encoder", "console", "Zap log encoding (one of 'json' or 'console')")
commandLine.IntVar(&enab, "logger-level-enabler", 127, "LevelEnabler decides whether a given logging level is enabled when logging a message")
commandLine.IntVar(&klogV, "logger-klog-v", 0, "number for klog level verbosity")
commandLine.StringVar(&file.Filename, "logger-filename", "", "File to write logs to")
commandLine.IntVar(&file.MaxSize, "logger-max-size", 100, "Maximum size in megabytes of the log file before it gets rotated")
commandLine.IntVar(&file.MaxAge, "logger-max-age", 7, "Maximum number of days to retain old log files based on the timestamp encoded in their filename")
commandLine.IntVar(&file.MaxBackups, "logger-max-backups", 7, "Maximum number of old log files to retain")
commandLine.BoolVar(&file.LocalTime, "logger-local-time", true, "LocalTime determines if the time used for formatting the timestamps in backup files is the computer's local time")
commandLine.BoolVar(&file.Compress, "logger-compress", false, "Compress determines if the rotated log files should be compressed using gzip")
}
// InitFlags is for explicitly initializing the flags.
// It may get called repeatedly for different flagSets, but not
// twice for the same one. May get called concurrently
// to other goroutines using logger. However, only some flags
// may get set concurrently.
func InitFlags(flagSet *flag.FlagSet) {
if flagSet == nil {
flagSet = flag.CommandLine
}
commandLine.VisitAll(func(f *flag.Flag) {
flagSet.Var(f.Value, f.Name, f.Usage)
})
}