This repository has been archived by the owner on May 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
consts.go
81 lines (66 loc) · 1.72 KB
/
consts.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
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
77
78
79
80
81
package config
import (
"fmt"
"strings"
"github.com/spf13/viper"
)
const (
KeyLogLevel = "log.level"
KeyCRDBDatabase = "crdb.database"
KeyCRDBHost = "crdb.host"
KeyCRDBPort = "crdb.port"
KeyCRDBUser = "crdb.user"
KeyCRDBPassword = "crdb.password"
KeyCRDBMode = "crdb.mode"
KeyAgentLogFormat = "agent.log-format"
KeyGoogleAgentEnable = "gops.enable"
KeyGoogleAgentBind = "gops.bind"
KeyGoogleAgentPort = "gops.port"
KeyPProfEnable = "pprof.enable"
KeyPProfBind = "pprof.bind"
KeyPProfPort = "pprof.port"
KeyHTTPServerBind = "http.bind"
KeyHTTPServerPort = "http.port"
KeyTritonDC = "triton.dc"
KeyTritonURL = "triton.url"
KeyTritonAuthURL = "triton.auth-url"
KeyTritonKeyPrefix = "triton.key-prefix"
KeyTritonWhitelist = "triton.whitelist"
KeyNomadURL = "nomad.url"
KeyNomadPort = "nomad.port"
)
const (
// Use a log format that resembles time.RFC3339Nano but includes all trailing
// zeros so that we get fixed-width logging.
LogTimeFormat = "2006-01-02T15:04:05.000000000Z07:00"
)
type LogFormat uint
const (
LogFormatAuto LogFormat = iota
LogFormatZerolog
LogFormatHuman
)
func (f LogFormat) String() string {
switch f {
case LogFormatAuto:
return "auto"
case LogFormatZerolog:
return "zerolog"
case LogFormatHuman:
return "human"
default:
panic(fmt.Sprintf("unknown log format: %d", f))
}
}
func LogLevelParse(s string) (LogFormat, error) {
switch logFormat := strings.ToLower(viper.GetString(KeyAgentLogFormat)); logFormat {
case "auto":
return LogFormatAuto, nil
case "json", "zerolog":
return LogFormatZerolog, nil
case "human":
return LogFormatHuman, nil
default:
return LogFormatAuto, fmt.Errorf("unsupported log format: %q", logFormat)
}
}