-
Notifications
You must be signed in to change notification settings - Fork 9
/
intercepter.go
35 lines (29 loc) · 938 Bytes
/
intercepter.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
package log
// Copyright 2019 Vivino. All rights reserved
//
// See LICENSE file for license details
// adapter is the stdlib logger adapter.
type interceptAdapter struct {
errCB func(msg string, keyvals ...interface{})
infCB func(msg string, keyvals ...interface{})
a Adapter
}
// Intercept can be used to intercept messages.
func Intercept(a Adapter, info, err func(msg string, keyvals ...interface{})) Adapter {
return &interceptAdapter{a: a, errCB: err, infCB: info}
}
func (a *interceptAdapter) Info(msg string, keyvals ...interface{}) {
if a.infCB != nil {
a.infCB(msg, keyvals...)
}
a.a.Info(msg, keyvals...)
}
func (a *interceptAdapter) Error(msg string, keyvals ...interface{}) {
if a.errCB != nil {
a.errCB(msg, keyvals...)
}
a.a.Error(msg, keyvals...)
}
func (a *interceptAdapter) New(keyvals ...interface{}) Adapter {
return &interceptAdapter{a: a.a.New(keyvals...), errCB: a.errCB, infCB: a.infCB}
}