-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlog.go
72 lines (59 loc) · 1.14 KB
/
log.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
package main
import (
"io"
"io/ioutil"
"log"
"os"
)
var (
Trace *log.Logger
Info *log.Logger
Warning *log.Logger
Error *log.Logger
Debug *log.Logger
)
type LogMode int
const (
DebugMode LogMode = iota
ReleaseMode
)
var Mode = DebugMode
func init() {
defaultLogger(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr,os.Stdout)
}
func defaultLogger(
traceHandle io.Writer,
infoHandle io.Writer,
warningHandle io.Writer,
errorHandle io.Writer,
debugHandle io.Writer) {
Trace = log.New(traceHandle,
"TRACE: ",
log.Ldate|log.Ltime|log.Lshortfile)
Info = log.New(infoHandle,
"INFO: ",
log.Ldate|log.Ltime|log.Lshortfile)
Warning = log.New(warningHandle,
"WARNING: ",
log.Ldate|log.Ltime|log.Lshortfile)
Error = log.New(errorHandle,
"ERROR: ",
log.Ldate|log.Ltime|log.Lshortfile)
Debug = log.New(debugHandle,
"DEBUG: ",
log.Ldate|log.Ltime|log.Lshortfile)
}
func SetLogMode(mode LogMode) {
Mode = mode
}
func SetWriter(w io.Writer) {
Trace.SetOutput(w)
Info.SetOutput(w)
Warning.SetOutput(w)
Error.SetOutput(w)
if Mode == DebugMode {
Debug.SetOutput(w)
}else {
Debug.SetOutput(ioutil.Discard)
}
}