-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlog.go
46 lines (35 loc) · 1.12 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
package djoemo
import (
"context"
)
type logger struct {
log LogInterface
}
// info logs info
func (l logger) info(ctx context.Context, table string, message string) {
l.log.WithFields(map[string]interface{}{TableName: table}).WithContext(ctx).Info(message)
}
// warn logs warning
func (l logger) warn(ctx context.Context, table string, message string) {
l.log.WithFields(map[string]interface{}{TableName: table}).WithContext(ctx).Warn(message)
}
// error logs error
func (l logger) error(ctx context.Context, table string, message string) {
l.log.WithFields(map[string]interface{}{TableName: table}).WithContext(ctx).Error(message)
}
//nopLog logger to turn off logging.
type nopLog struct{}
// WithContext adds context to logger
func (l nopLog) WithContext(ctx context.Context) LogInterface {
return l
}
// WithFields adds fields from map string interface to logger
func (l nopLog) WithFields(fields map[string]interface{}) LogInterface {
return l
}
// info logs info
func (l nopLog) Info(message string) {}
// warn logs warning
func (l nopLog) Warn(message string) {}
// info logs info
func (l nopLog) Error(message string) {}