-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlogging.go
More file actions
63 lines (58 loc) · 954 Bytes
/
logging.go
File metadata and controls
63 lines (58 loc) · 954 Bytes
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
package main
import (
"fmt"
)
type LogLevel int
const (
Info LogLevel = iota
Warn
Err
Panic
)
func (d *Data) LogInfoHeader() {
if !d.InfoHeader {
d.InfoHeader = true
fmt.Printf(WithoutColor, "\n["+FindRootKey[d.RootKey]+"\\"+d.StringPath+"]")
}
}
func (d *Data) Log(level LogLevel, line string) {
switch level {
case Info:
if !NoInfo {
d.LogInfoHeader()
if NoColor {
fmt.Printf(WithoutColor, line)
} else {
fmt.Printf(InfoColor, line)
}
}
case Warn:
if !NoWarn {
d.LogInfoHeader()
if NoColor {
fmt.Printf(WithoutColor, line)
} else {
fmt.Printf(WarningColor, line)
}
}
issues++
case Err:
if !NoErr {
d.LogInfoHeader()
if NoColor {
fmt.Printf(WithoutColor, line)
} else {
fmt.Printf(ErrorColor, line)
}
}
issues++
case Panic:
d.LogInfoHeader()
if NoColor {
fmt.Printf(WithoutColor, line)
} else {
fmt.Printf(PanicColor, line)
}
issues++
}
}