-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
46 lines (36 loc) · 1023 Bytes
/
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 log
import (
"context"
)
// Log interface
type Log interface {
Debug(keysAndValues ...interface{})
Debugw(msg string, keysAndValues ...interface{})
Debugf(format string, a ...interface{})
Info(keysAndValues ...interface{})
Infow(msg string, keysAndValues ...interface{})
Infof(format string, a ...interface{})
Warn(keysAndValues ...interface{})
Warnw(msg string, keysAndValues ...interface{})
Warnf(format string, a ...interface{})
Error(keysAndValues ...interface{})
Errorw(msg string, keysAndValues ...interface{})
Errorf(format string, a ...interface{})
With(keysAndValues ...interface{})
Flush() error
Clone() Log
}
type logKey struct{}
var (
// DefaultLog default use uber log
Logger = NewLog()
)
// NewContext put Log to context
func NewContext(ctx context.Context, l Log) context.Context {
return context.WithValue(ctx, logKey{}, l)
}
// FromContext get Log from context
func FromContext(ctx context.Context) (Log, bool) {
log, ok := ctx.Value(logKey{}).(Log)
return log, ok
}