-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
68 lines (55 loc) · 1.09 KB
/
logger.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
package logger
import (
"io"
"os"
)
const (
Cyan = 36
Yellow = 33
Red = 31
Reset = 0
)
const (
DEBUG = "DEBUG"
INFO = "INFO"
WARN = "WARN"
ERROR = "ERROR"
)
var Default = &Logger{
appenders: []*appender{
{output: os.Stdout},
},
}
type Logger struct {
appenders []*appender
}
func New(outputs ...io.Writer) *Logger {
var appenders []*appender
for _, output := range outputs {
appenders = append(appenders, &appender{output: output})
}
return &Logger{appenders: appenders}
}
func (l *Logger) Add(appender *appender) {
l.appenders = append(l.appenders, appender)
}
func (l *Logger) Debug(mensage interface{}) {
for _, appender := range l.appenders {
appender.log(DEBUG, Reset, mensage)
}
}
func (l *Logger) Info(mensage interface{}) {
for _, appender := range l.appenders {
appender.log(INFO, Cyan, mensage)
}
}
func (l *Logger) Error(mensage interface{}) {
for _, appender := range l.appenders {
appender.log(ERROR, Red, mensage)
}
}
func (l *Logger) Warn(mensage interface{}) {
for _, appender := range l.appenders {
appender.log(WARN, Yellow, mensage)
}
}