@@ -12,10 +12,10 @@ import (
12
12
"time"
13
13
14
14
writer "github.com/ipfs/go-log/writer"
15
- "github.com/whyrusleeping/go-logging"
16
15
17
16
opentrace "github.com/opentracing/opentracing-go"
18
17
otExt "github.com/opentracing/opentracing-go/ext"
18
+ "go.uber.org/zap"
19
19
)
20
20
21
21
var log = Logger ("eventlog" )
@@ -159,46 +159,48 @@ type EventLogger interface {
159
159
SerializeContext (ctx context.Context ) ([]byte , error )
160
160
}
161
161
162
- // Logger retrieves an event logger by name
163
- func Logger (system string ) EventLogger {
162
+ var _ EventLogger = Logger ("test-logger" )
164
163
165
- // TODO if we would like to adjust log levels at run-time. Store this event
166
- // logger in a map (just like the util.Logger impl)
164
+ // Logger retrieves an event logger by name
165
+ func Logger ( system string ) * ZapEventLogger {
167
166
if len (system ) == 0 {
168
167
setuplog := getLogger ("setup-logger" )
169
- setuplog .Warning ("Missing name parameter" )
168
+ setuplog .Error ("Missing name parameter" )
170
169
system = "undefined"
171
170
}
172
171
173
172
logger := getLogger (system )
174
173
175
- return & eventLogger {system : system , Logger : * logger }
174
+ return & ZapEventLogger {system : system , SugaredLogger : * logger }
176
175
}
177
176
178
- // eventLogger implements the EventLogger and wraps a go-logging Logger
179
- type eventLogger struct {
180
- logging. Logger
177
+ // ZapEventLogger implements the EventLogger and wraps a go-logging Logger
178
+ type ZapEventLogger struct {
179
+ zap. SugaredLogger
181
180
182
181
system string
183
182
// TODO add log-level
184
183
}
185
184
186
- func (el * eventLogger ) Warn (args ... interface {}) {
187
- el .Warning (args ... )
185
+ // Deprecated: use Warn
186
+ func (el * ZapEventLogger ) Warning (args ... interface {}) {
187
+ el .Warn (args ... )
188
188
}
189
- func (el * eventLogger ) Warnf (format string , args ... interface {}) {
190
- el .Warningf (format , args ... )
189
+
190
+ // Deprecated: use Warnf
191
+ func (el * ZapEventLogger ) Warningf (format string , args ... interface {}) {
192
+ el .Warnf (format , args ... )
191
193
}
192
194
193
195
// Deprecated: Stop using go-log for event logging
194
- func (el * eventLogger ) Start (ctx context.Context , operationName string ) context.Context {
196
+ func (el * ZapEventLogger ) Start (ctx context.Context , operationName string ) context.Context {
195
197
span , ctx := opentrace .StartSpanFromContext (ctx , operationName )
196
198
span .SetTag ("system" , el .system )
197
199
return ctx
198
200
}
199
201
200
202
// Deprecated: Stop using go-log for event logging
201
- func (el * eventLogger ) StartFromParentState (ctx context.Context , operationName string , parent []byte ) (context.Context , error ) {
203
+ func (el * ZapEventLogger ) StartFromParentState (ctx context.Context , operationName string , parent []byte ) (context.Context , error ) {
202
204
sc , err := deserializeContext (parent )
203
205
if err != nil {
204
206
return nil , err
@@ -211,7 +213,7 @@ func (el *eventLogger) StartFromParentState(ctx context.Context, operationName s
211
213
}
212
214
213
215
// Deprecated: Stop using go-log for event logging
214
- func (el * eventLogger ) SerializeContext (ctx context.Context ) ([]byte , error ) {
216
+ func (el * ZapEventLogger ) SerializeContext (ctx context.Context ) ([]byte , error ) {
215
217
gTracer := opentrace .GlobalTracer ()
216
218
b := make ([]byte , 0 )
217
219
carrier := bytes .NewBuffer (b )
@@ -223,7 +225,7 @@ func (el *eventLogger) SerializeContext(ctx context.Context) ([]byte, error) {
223
225
}
224
226
225
227
// Deprecated: Stop using go-log for event logging
226
- func (el * eventLogger ) LogKV (ctx context.Context , alternatingKeyValues ... interface {}) {
228
+ func (el * ZapEventLogger ) LogKV (ctx context.Context , alternatingKeyValues ... interface {}) {
227
229
span := opentrace .SpanFromContext (ctx )
228
230
if span == nil {
229
231
_ , file , line , _ := runtime .Caller (1 )
@@ -234,7 +236,7 @@ func (el *eventLogger) LogKV(ctx context.Context, alternatingKeyValues ...interf
234
236
}
235
237
236
238
// Deprecated: Stop using go-log for event logging
237
- func (el * eventLogger ) SetTag (ctx context.Context , k string , v interface {}) {
239
+ func (el * ZapEventLogger ) SetTag (ctx context.Context , k string , v interface {}) {
238
240
span := opentrace .SpanFromContext (ctx )
239
241
if span == nil {
240
242
_ , file , line , _ := runtime .Caller (1 )
@@ -245,7 +247,7 @@ func (el *eventLogger) SetTag(ctx context.Context, k string, v interface{}) {
245
247
}
246
248
247
249
// Deprecated: Stop using go-log for event logging
248
- func (el * eventLogger ) SetTags (ctx context.Context , tags map [string ]interface {}) {
250
+ func (el * ZapEventLogger ) SetTags (ctx context.Context , tags map [string ]interface {}) {
249
251
span := opentrace .SpanFromContext (ctx )
250
252
if span == nil {
251
253
_ , file , line , _ := runtime .Caller (1 )
@@ -257,7 +259,7 @@ func (el *eventLogger) SetTags(ctx context.Context, tags map[string]interface{})
257
259
}
258
260
}
259
261
260
- func (el * eventLogger ) setErr (ctx context.Context , err error , skip int ) {
262
+ func (el * ZapEventLogger ) setErr (ctx context.Context , err error , skip int ) {
261
263
span := opentrace .SpanFromContext (ctx )
262
264
if span == nil {
263
265
_ , file , line , _ := runtime .Caller (skip )
@@ -273,12 +275,12 @@ func (el *eventLogger) setErr(ctx context.Context, err error, skip int) {
273
275
}
274
276
275
277
// Deprecated: Stop using go-log for event logging
276
- func (el * eventLogger ) SetErr (ctx context.Context , err error ) {
278
+ func (el * ZapEventLogger ) SetErr (ctx context.Context , err error ) {
277
279
el .setErr (ctx , err , 1 )
278
280
}
279
281
280
282
// Deprecated: Stop using go-log for event logging
281
- func (el * eventLogger ) Finish (ctx context.Context ) {
283
+ func (el * ZapEventLogger ) Finish (ctx context.Context ) {
282
284
span := opentrace .SpanFromContext (ctx )
283
285
if span == nil {
284
286
_ , file , line , _ := runtime .Caller (1 )
@@ -289,7 +291,7 @@ func (el *eventLogger) Finish(ctx context.Context) {
289
291
}
290
292
291
293
// Deprecated: Stop using go-log for event logging
292
- func (el * eventLogger ) FinishWithErr (ctx context.Context , err error ) {
294
+ func (el * ZapEventLogger ) FinishWithErr (ctx context.Context , err error ) {
293
295
el .setErr (ctx , err , 2 )
294
296
el .Finish (ctx )
295
297
}
@@ -306,7 +308,7 @@ func deserializeContext(bCtx []byte) (opentrace.SpanContext, error) {
306
308
}
307
309
308
310
// Deprecated: Stop using go-log for event logging
309
- func (el * eventLogger ) EventBegin (ctx context.Context , event string , metadata ... Loggable ) * EventInProgress {
311
+ func (el * ZapEventLogger ) EventBegin (ctx context.Context , event string , metadata ... Loggable ) * EventInProgress {
310
312
ctx = el .Start (ctx , event )
311
313
312
314
for _ , m := range metadata {
@@ -329,12 +331,8 @@ func (el *eventLogger) EventBegin(ctx context.Context, event string, metadata ..
329
331
return eip
330
332
}
331
333
332
- type activeEventKeyType struct {}
333
-
334
- var activeEventKey = activeEventKeyType {}
335
-
336
334
// Deprecated: Stop using go-log for event logging
337
- func (el * eventLogger ) Event (ctx context.Context , event string , metadata ... Loggable ) {
335
+ func (el * ZapEventLogger ) Event (ctx context.Context , event string , metadata ... Loggable ) {
338
336
339
337
// short circuit if theres nothing to write to
340
338
if ! writer .WriterGroup .Active () {
0 commit comments