-
Notifications
You must be signed in to change notification settings - Fork 8
/
logging.go
67 lines (56 loc) · 1.23 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
package kubexp
import (
"io"
"io/ioutil"
"log"
"os"
"strings"
)
var (
tracelog *log.Logger
infolog *log.Logger
warninglog *log.Logger
errorlog *log.Logger
fatalStderrlog *log.Logger
warnStderrlog *log.Logger
)
func initLog(writer io.Writer) {
fatalStderrlog = log.New(os.Stderr,
"FATAL: ",
log.Ldate|log.Ltime|log.Lshortfile)
warnStderrlog = log.New(os.Stderr,
"WARN: ",
log.Ldate|log.Ltime|log.Lshortfile)
traceWriter := ioutil.Discard
infoWriter := ioutil.Discard
warningWriter := ioutil.Discard
errorWriter := ioutil.Discard
switch strings.ToLower(*logLevel) {
case "trace":
traceWriter = writer
fallthrough
case "info":
infoWriter = writer
fallthrough
case "warn":
warningWriter = writer
fallthrough
case "error":
errorWriter = writer
default:
fatalStderrlog.Panicf("Loglevel: '%s' not supported!", *logLevel)
}
tracelog = log.New(traceWriter,
"TRACE: ",
log.Ldate|log.Ltime|log.Lshortfile)
infolog = log.New(infoWriter,
"INFO: ",
log.Ldate|log.Ltime|log.Lshortfile)
warninglog = log.New(warningWriter,
"WARN: ",
log.Ldate|log.Ltime|log.Lshortfile)
errorlog = log.New(errorWriter,
"ERROR: ",
log.Ldate|log.Ltime|log.Lshortfile)
//defer logFile.Close()
}