-
Notifications
You must be signed in to change notification settings - Fork 7
/
configuration.go
67 lines (60 loc) · 2.11 KB
/
configuration.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
package astilog
import (
"flag"
"github.com/asticode/go-astikit"
)
// Flags
var (
AppName = flag.String("logger-app-name", "", "the logger app name")
Filename = flag.String("logger-filename", "", "the logger filename")
Format = flag.String("logger-format", "", "the logger format")
Level = flag.String("logger-level", "", "the logger level")
MaxWriteLength = flag.Int("logger-max-write-length", 0, "the logger max write length")
MessageKey = flag.String("logger-message-key", "", "the logger message key")
Out = flag.String("logger-out", "", "the logger out")
Source = flag.Bool("logger-source", false, "if true, then source is added to fields")
TimestampFormat = flag.String("logger-timestamp-format", "", "the logger timestamp format")
Verbose = flag.Bool("v", false, "if true, then log level is debug")
)
// Formats
const (
FormatJSON = "json"
FormatMinimalist = "minimalist"
FormatText = "text"
)
// Outs
const (
OutStderr = "stderr"
OutStdout = "stdout"
OutSyslog = "syslog"
)
// Configuration represents the configuration of the logger
type Configuration struct {
AppName string `toml:"app_name"`
Filename string `toml:"filename"`
Format string `toml:"format"`
Level astikit.LoggerLevel `toml:"level"`
MaxWriteLength int `toml:"max_write_length"`
MessageKey string `toml:"message_key"`
Out string `toml:"out"`
Source bool `toml:"source"`
TimestampFormat string `toml:"timestamp_format"`
}
// FlagConfig generates a Configuration based on flags
func FlagConfig() (c Configuration) {
c = Configuration{
AppName: *AppName,
Filename: *Filename,
Format: *Format,
Level: astikit.LoggerLevelFromString(*Level),
MaxWriteLength: *MaxWriteLength,
MessageKey: *MessageKey,
Out: *Out,
Source: *Source,
TimestampFormat: *TimestampFormat,
}
if *Verbose {
c.Level = astikit.LoggerLevelDebug
}
return
}