-
Notifications
You must be signed in to change notification settings - Fork 0
/
log_format.go
53 lines (46 loc) · 903 Bytes
/
log_format.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
package goslog
import (
"fmt"
"strings"
)
type LogFormat int
const (
FORMAT_PRETTY LogFormat = iota
FORMAT_TEXT
FORMAT_JSON
)
// UnmarshalFlag converts a string to a CookieDomain
func (l *LogFormat) UnmarshalFlag(value string) error {
return l.Set(value)
}
// MarshalFlag converts a CookieDomain to a string
func (l *LogFormat) MarshalFlag() (string, error) {
return l.String(), nil
}
// implements [flag.Value]
func (l LogFormat) String() string {
switch l {
case FORMAT_PRETTY:
return "pretty"
case FORMAT_TEXT:
return "text"
case FORMAT_JSON:
return "json"
default:
return ""
}
}
// implements [flag.Value]
func (l *LogFormat) Set(value string) error {
switch strings.ToLower(string(value)) {
case "pretty":
*l = FORMAT_PRETTY
case "text":
*l = FORMAT_TEXT
case "json":
*l = FORMAT_JSON
default:
return fmt.Errorf("unkown log format: %d", l)
}
return nil
}