-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogger.go
167 lines (135 loc) · 4.37 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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
package echo
import (
"io"
"io/ioutil"
"github.com/labstack/echo/v4"
"github.com/labstack/gommon/log"
"go.uber.org/zap"
)
type (
echoLogger struct {
l *zap.SugaredLogger
}
)
// NewLogger converts zap.Logger to echo.Logger
func NewLogger(log *zap.Logger) echo.Logger {
return &echoLogger{
l: log.
WithOptions(zap.AddCallerSkip(1)).
Sugar(),
}
}
// Output writer
func (e *echoLogger) Output() io.Writer {
return ioutil.Discard
}
// SetOutput do nothing
func (e *echoLogger) SetOutput(w io.Writer) {}
// SetHeader do nothing
func (e *echoLogger) SetHeader(h string) {}
// Prefix do nothing
func (e *echoLogger) Prefix() string {
return ""
}
// SetPrefix do nothing
func (e *echoLogger) SetPrefix(p string) {}
// Level do nothing
func (e *echoLogger) Level() log.Lvl {
return log.DEBUG
}
// SetLevel do nothing
func (e *echoLogger) SetLevel(v log.Lvl) {}
// Print uses fmt.Sprint to construct and log a message.
func (e *echoLogger) Print(i ...interface{}) {
e.l.Info(i...)
}
// Printf uses fmt.Sprintf to log a templated message.
func (e *echoLogger) Printf(format string, args ...interface{}) {
e.l.Infof(format, args...)
}
// Printj logs a message with some additional context. The variadic key-value
// pairs are treated as they are in With.
func (e *echoLogger) Printj(j log.JSON) {
e.l.Infow("echo json log", "json_msg", j)
}
// Debug uses fmt.Sprint to construct and log a message.
func (e *echoLogger) Debug(i ...interface{}) {
e.l.Debug(i...)
}
// Debugf uses fmt.Sprintf to log a templated message.
func (e *echoLogger) Debugf(format string, args ...interface{}) {
e.l.Debugf(format, args...)
}
// Debugj logs a message with some additional context. The variadic key-value
// pairs are treated as they are in With.
//
// When debug-level logging is disabled, this is much faster than
// s.With(keysAndValues).Debug(msg)
func (e *echoLogger) Debugj(j log.JSON) {
e.l.Debugw("echo json log", "json_msg", j)
}
// Info uses fmt.Sprint to construct and log a message.
func (e *echoLogger) Info(i ...interface{}) {
e.l.Info(i...)
}
// Infof uses fmt.Sprintf to log a templated message.
func (e *echoLogger) Infof(format string, args ...interface{}) {
e.l.Infof(format, args...)
}
// Infoj logs a message with some additional context. The variadic key-value
// pairs are treated as they are in With.
func (e *echoLogger) Infoj(j log.JSON) {
e.l.Infow("echo json log", "json_msg", j)
}
// Warn uses fmt.Sprint to construct and log a message.
func (e *echoLogger) Warn(i ...interface{}) {
e.l.Warn(i...)
}
// Warnf uses fmt.Sprintf to log a templated message.
func (e *echoLogger) Warnf(format string, args ...interface{}) {
e.l.Warnf(format, args...)
}
// Warnj logs a message with some additional context. The variadic key-value
// pairs are treated as they are in With.
func (e *echoLogger) Warnj(j log.JSON) {
e.l.Warnw("echo json log", "json_msg", j)
}
// Error uses fmt.Sprint to construct and log a message.
func (e *echoLogger) Error(i ...interface{}) {
e.l.Error(i...)
}
// Errorf uses fmt.Sprintf to log a templated message.
func (e *echoLogger) Errorf(format string, args ...interface{}) {
e.l.Errorf(format, args...)
}
// Errorj logs a message with some additional context. The variadic key-value
// pairs are treated as they are in With.
func (e *echoLogger) Errorj(j log.JSON) {
e.l.Errorw("echo json log", "json_msg", j)
}
// Fatal uses fmt.Sprint to construct and log a message, then calls os.Exit.
func (e *echoLogger) Fatal(i ...interface{}) {
e.l.Fatal(i...)
}
// Fatalf uses fmt.Sprintf to log a templated message, then calls os.Exit.
func (e *echoLogger) Fatalf(format string, args ...interface{}) {
e.l.Fatalf(format, args...)
}
// Fatalj logs a message with some additional context, then calls os.Exit. The
// variadic key-value pairs are treated as they are in With.
func (e *echoLogger) Fatalj(j log.JSON) {
e.l.Fatalw("echo json log", "json_msg", j)
}
// Panic uses fmt.Sprint to construct and log a message, then panics.
func (e *echoLogger) Panic(i ...interface{}) {
e.l.Panic(i...)
}
// Panicf uses fmt.Sprintf to log a templated message, then panics.
func (e *echoLogger) Panicf(format string, args ...interface{}) {
e.l.Panicf(format, args...)
}
// Panicj logs a message with some additional context, then panics. The
// variadic key-value pairs are treated as they are in With.
func (e *echoLogger) Panicj(j log.JSON) {
e.l.Panicw("echo json log", "json_msg", j)
}