-
Notifications
You must be signed in to change notification settings - Fork 0
/
logs.go
72 lines (58 loc) · 1.43 KB
/
logs.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"
"log"
"os"
)
var (
Trace *log.Logger
Info *log.Logger
Warning *log.Logger
Error *log.Logger
Debug *log.Logger
)
func initlog(
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 InitLogging(t, i, w, e, d bool) {
fileTrace := os.Stdout
if t == true {
fileTrace, _ = os.OpenFile("trace.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
}
fileInfo := os.Stdout
if i == true {
fileInfo, _ = os.OpenFile("info.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
}
fileWarning := os.Stdout
if w == true {
fileWarning, _ = os.OpenFile("warning.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
}
fileError := os.Stdout
if e == true {
fileError, _ = os.OpenFile("error.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
}
fileDebug := os.Stdout
if d == true {
fileDebug, _ = os.OpenFile("debug.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666)
}
initlog(fileTrace, fileInfo, fileWarning, fileError, fileDebug)
}