-
Notifications
You must be signed in to change notification settings - Fork 0
/
consolewriter.go
61 lines (51 loc) · 1.12 KB
/
consolewriter.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
package l3
import (
"bufio"
"io"
"os"
)
// ConsoleWriter struct
type ConsoleWriter struct {
errorWriter, warnWriter, infoWriter, debugWriter, traceWriter io.Writer
}
// InitConfig ConsoleWriter
func (cw *ConsoleWriter) InitConfig(w *WriterConfig) {
if w.Console.WriteErrToStdOut {
cw.errorWriter = bufio.NewWriter(os.Stdout)
} else {
cw.errorWriter = bufio.NewWriter(os.Stderr)
}
if w.Console.WriteWarnToStdOut {
cw.warnWriter = bufio.NewWriter(os.Stdout)
} else {
cw.warnWriter = bufio.NewWriter(os.Stderr)
}
cw.infoWriter = bufio.NewWriter(os.Stdout)
cw.debugWriter = bufio.NewWriter(os.Stdout)
cw.traceWriter = bufio.NewWriter(os.Stdout)
}
// DoLog consoleWriter
func (cw *ConsoleWriter) DoLog(logMsg *LogMessage) {
var writer io.Writer
switch logMsg.Level {
case Off:
break
case Err:
writer = cw.errorWriter
case Warn:
writer = cw.warnWriter
case Info:
writer = cw.infoWriter
case Debug:
writer = cw.debugWriter
case Trace:
writer = cw.traceWriter
}
if writer != nil {
writeLogMsg(writer, logMsg)
}
}
// Close close ConsoleWriter
func (cw *ConsoleWriter) Close() error {
return nil
}