forked from golangci/golangci-lint
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logutils.go
48 lines (37 loc) · 831 Bytes
/
logutils.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
package logutils
import (
"os"
"strings"
)
func getEnabledDebugs() map[string]bool {
ret := map[string]bool{}
debugVar := os.Getenv("GL_DEBUG")
if debugVar == "" {
return ret
}
for _, tag := range strings.Split(debugVar, ",") {
ret[tag] = true
}
return ret
}
var enabledDebugs = getEnabledDebugs()
type DebugFunc func(format string, args ...interface{})
func nopDebugf(format string, args ...interface{}) {}
func Debug(tag string) DebugFunc {
if !enabledDebugs[tag] {
return nopDebugf
}
return func(format string, args ...interface{}) {
logger := NewStderrLog(tag)
logger.SetLevel(LogLevelDebug)
logger.Debugf(format, args...)
}
}
func HaveDebugTag(tag string) bool {
return enabledDebugs[tag]
}
func SetupVerboseLog(log Log, isVerbose bool) {
if isVerbose {
log.SetLevel(LogLevelInfo)
}
}