-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
45 lines (36 loc) · 1.21 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
package sqlxx
import (
"context"
"io"
"log"
)
type loggerFunc func(ctx context.Context, format string, args ...interface{})
type Logger interface {
Debugf(ctx context.Context, format string, args ...interface{})
Infof(ctx context.Context, format string, args ...interface{})
Warnf(ctx context.Context, format string, args ...interface{})
Errorf(ctx context.Context, format string, args ...interface{})
}
type LoggerImpl struct {
debug, info, warn, err *log.Logger
}
func NewLogger(out io.Writer) Logger {
return &LoggerImpl{
debug: log.New(out, "[DEBUG] ", log.LstdFlags),
info: log.New(out, "[INFO] ", log.LstdFlags),
warn: log.New(out, "[WARN] ", log.LstdFlags),
err: log.New(out, "[ERROR] ", log.LstdFlags),
}
}
func (li *LoggerImpl) Debugf(ctx context.Context, format string, args ...interface{}) {
li.debug.Printf(format, args...)
}
func (li *LoggerImpl) Infof(ctx context.Context, format string, args ...interface{}) {
li.info.Printf(format, args...)
}
func (li *LoggerImpl) Warnf(ctx context.Context, format string, args ...interface{}) {
li.warn.Printf(format, args...)
}
func (li *LoggerImpl) Errorf(ctx context.Context, format string, args ...interface{}) {
li.err.Printf(format, args...)
}