-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlog.go
59 lines (49 loc) · 1.1 KB
/
log.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
package auth
import (
log "git.sr.ht/~mariusor/lw"
)
type LoggerFn func(log.Ctx, string, ...interface{})
type logger struct {
logFn LoggerFn
errFn LoggerFn
}
type optionFn func(*logger) error
func LogFn(logFn LoggerFn) optionFn {
return func(l *logger) error {
l.logFn = logFn
return nil
}
}
func ErrFn(logFn LoggerFn) optionFn {
return func(l *logger) error {
l.errFn = logFn
return nil
}
}
func NewLogger(opt ...optionFn) (*logger, error) {
l := new(logger)
l.errFn = EmptyLogFn
l.logFn = EmptyLogFn
for _, fn := range opt {
if err := fn(l); err != nil {
return nil, err
}
}
return l, nil
}
var EmptyLogFn = func(log.Ctx, string, ...interface{}) {}
func (l logger) Printf(format string, v ...interface{}) {
l.logFn(nil, format, v...)
}
func (l logger) Errorf(format string, v ...interface{}) {
l.errFn(nil, format, v...)
}
func (l logger) Warningf(format string, v ...interface{}) {
l.logFn(nil, format, v...)
}
func (l logger) Infof(format string, v ...interface{}) {
l.logFn(nil, format, v...)
}
func (l logger) Debugf(format string, v ...interface{}) {
l.logFn(nil, format, v...)
}