-
Notifications
You must be signed in to change notification settings - Fork 0
/
logging.go
44 lines (37 loc) · 746 Bytes
/
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
package heatmap
import (
"io"
"io/ioutil"
"log"
"os"
"strings"
)
var logInfo = log.New(ioutil.Discard, "[INFO] ", log.Ldate|log.Ltime|log.LUTC)
var logDebug = log.New(ioutil.Discard, "[DEBUG] ", log.Ldate|log.Ltime|log.LUTC)
var logError = log.New(ioutil.Discard, "[ERROR] ", log.Ldate|log.Ltime|log.LUTC)
var loggers = []*log.Logger{
logInfo,
logDebug,
logError,
}
var logLevels = []string{
"info",
"debug",
"error",
}
func changeLogLevel(newLevel string) {
newLevel = strings.ToLower(newLevel)
newIndex := -1
for i, l := range logLevels {
if l == newLevel {
newIndex = i
}
}
output := io.Writer(os.Stdout)
for i, l := range loggers {
if i > newIndex {
output = ioutil.Discard
}
l.SetOutput(output)
}
}