-
Notifications
You must be signed in to change notification settings - Fork 1
/
logging.go
88 lines (77 loc) · 1.65 KB
/
logging.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
82
83
84
85
86
87
88
package main
import (
"log"
"strings"
)
type LogLevel byte
const (
logUnknown LogLevel = iota
logVerboseDebug
logDebug
logInfo
logWarning
logCritical
)
// returns the string value of the LogLevel
func (ll LogLevel) String() string {
switch ll {
case logVerboseDebug:
return "VerboseDebug"
case logDebug:
return "Debug"
case logInfo:
return "Info"
case logWarning:
return "Warning"
case logCritical:
return "Critical"
}
return "Unknown"
}
// return the LogLevel from string input
func getLogLevel(s string) LogLevel {
switch strings.ToLower(s) {
case "verbosedebug":
return logVerboseDebug
case "debug":
return logDebug
case "info":
return logInfo
case "warning":
return logWarning
case "critical":
return logCritical
}
return logUnknown
}
type LogFunction func(string, ...interface{})
// LogDVf prints Verbose Debug logs
func LogDVf(format string, args ...interface{}) {
if lobbySettings.logLevel <= logVerboseDebug {
log.Printf("[DEBUG VERBOSE] "+format, args...)
}
}
// LogDf prints Debug logs
func LogDf(format string, args ...interface{}) {
if lobbySettings.logLevel <= logDebug {
log.Printf("[DEBUG] "+format, args...)
}
}
// LogIf prints Info logs
func LogIf(format string, args ...interface{}) {
if lobbySettings.logLevel <= logInfo {
log.Printf("[INFO] "+format, args...)
}
}
// LogWf prints Warning logs
func LogWf(format string, args ...interface{}) {
if lobbySettings.logLevel <= logWarning {
log.Printf("[WARNING] "+format, args...)
}
}
// LogCf prints Critical logs
func LogCf(format string, args ...interface{}) {
if lobbySettings.logLevel <= logCritical {
log.Printf("[CRITICAL] "+format, args...)
}
}