-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
logger.go
128 lines (96 loc) · 2.63 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package logrus
import (
"context"
"fmt"
"io"
"github.com/sirupsen/logrus"
)
type Writer struct {
log *logrus.Logger
}
func NewWriter(opts ...Option) *Writer {
cfg := defaultConfig()
// apply options
for _, opt := range opts {
opt.apply(cfg)
}
// default trace hooks
cfg.hooks = append(cfg.hooks, NewTraceHook(cfg.traceHookConfig))
// attach hook
for _, hook := range cfg.hooks {
cfg.logger.AddHook(hook)
}
return &Writer{log: cfg.logger}
}
func (w *Writer) Logger() *logrus.Logger {
return w.log
}
func (w *Writer) Trace(v ...interface{}) {
w.log.Trace(v...)
}
func (w *Writer) Debug(v ...interface{}) {
w.log.Debug(v...)
}
func (w *Writer) Info(v ...interface{}) {
w.log.Info(v...)
}
func (w *Writer) Notice(v ...interface{}) {
w.log.Warn(v...)
}
func (w *Writer) Warn(v ...interface{}) {
w.log.Warn(v...)
}
func (w *Writer) Error(v ...interface{}) {
w.log.Error(v...)
}
func (w *Writer) Fatal(v ...interface{}) {
w.log.Fatal(v...)
}
func (w *Writer) Tracef(format string, v ...interface{}) {
w.log.Tracef(format, v...)
}
func (w *Writer) Debugf(format string, v ...interface{}) {
w.log.Debugf(format, v...)
}
func (w *Writer) Infof(format string, v ...interface{}) {
w.log.Infof(format, v...)
}
func (w *Writer) Noticef(format string, v ...interface{}) {
w.log.Warnf(format, v...)
}
func (w *Writer) Warnf(format string, v ...interface{}) {
w.log.Warnf(format, v...)
}
func (w *Writer) Errorf(format string, v ...interface{}) {
w.log.Errorf(format, v...)
}
func (w *Writer) Fatalf(format string, v ...interface{}) {
w.log.Fatalf(format, v...)
}
func (w *Writer) CtxTracef(ctx context.Context, format string, v ...interface{}) {
w.log.WithContext(ctx).Tracef(format, v...)
}
func (w *Writer) CtxDebugf(ctx context.Context, format string, v ...interface{}) {
w.log.WithContext(ctx).Debugf(format, v...)
}
func (w *Writer) CtxInfof(ctx context.Context, format string, v ...interface{}) {
w.log.WithContext(ctx).Infof(format, v...)
}
func (w *Writer) CtxNoticef(ctx context.Context, format string, v ...interface{}) {
w.log.WithContext(ctx).Warnf(format, v...)
}
func (w *Writer) CtxWarnf(ctx context.Context, format string, v ...interface{}) {
w.log.WithContext(ctx).Warnf(format, v...)
}
func (w *Writer) CtxErrorf(ctx context.Context, format string, v ...interface{}) {
w.log.WithContext(ctx).Errorf(format, v...)
}
func (w *Writer) CtxFatalf(ctx context.Context, format string, v ...interface{}) {
w.log.WithContext(ctx).Fatalf(format, v...)
}
func (w *Writer) SetOutput(writer io.Writer) {
w.log.SetOutput(writer)
}
func (w *Writer) Printf(format string, v ...interface{}) {
w.log.Info(fmt.Sprintf(format, v...))
}