-
Notifications
You must be signed in to change notification settings - Fork 3
/
logger.go
51 lines (39 loc) · 1.11 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
package gol
import (
"github.com/philchia/gol/adapter"
"github.com/philchia/gol/adapter/console"
"github.com/philchia/gol/level"
)
// Logger ...
type Logger interface {
Debug(i ...interface{})
Debugf(format string, i ...interface{})
Info(i ...interface{})
Infof(format string, i ...interface{})
Warn(i ...interface{})
Warnf(format string, i ...interface{})
Error(i ...interface{})
Errorf(format string, i ...interface{})
Critical(i ...interface{})
Criticalf(format string, i ...interface{})
SetLevel(level.LogLevel)
SetOption(LogOption)
AddLogAdapter(name string, adapter adapter.Adapter) error
RemoveAdapter(name string) error
Flush()
}
// CONSOLELOGGER represent the given console adapter name
const CONSOLELOGGER = "console"
// NewLogger create a Logger with given log level
func NewLogger(level level.LogLevel) Logger {
logger := &gollog{
level: level,
option: LstdFlags,
logChan: make(chan *logMSG, 10240),
doneChan: make(chan struct{}),
adapters: make(map[string]adapter.Adapter, 1),
}
logger.AddLogAdapter(CONSOLELOGGER, console.NewAdapter())
go logger.msgPump()
return logger
}