-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
context_with_logging.go
52 lines (39 loc) · 1.29 KB
/
context_with_logging.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
package logger
import (
"golang.org/x/net/context"
)
type Context struct {
ctx context.Context
Logger
}
var _ ContextInterface = Context{}
func (c Context) Ctx() context.Context {
return c.ctx
}
func NewContext(c context.Context, l Logger) Context {
return Context{ctx: c, Logger: l}
}
func (c Context) UpdateContextToLoggerContext(ctx context.Context) ContextInterface {
return NewContext(ctx, c.Logger)
}
func (c Context) Debug(format string, arg ...interface{}) {
c.Logger.CloneWithAddedDepth(1).CDebugf(c.ctx, format, arg...)
}
func (c Context) Info(format string, arg ...interface{}) {
c.Logger.CloneWithAddedDepth(1).CInfof(c.ctx, format, arg...)
}
func (c Context) Notice(format string, arg ...interface{}) {
c.Logger.CloneWithAddedDepth(1).CNoticef(c.ctx, format, arg...)
}
func (c Context) Warning(format string, arg ...interface{}) {
c.Logger.CloneWithAddedDepth(1).CWarningf(c.ctx, format, arg...)
}
func (c Context) Error(format string, arg ...interface{}) {
c.Logger.CloneWithAddedDepth(1).CErrorf(c.ctx, format, arg...)
}
func (c Context) Critical(format string, arg ...interface{}) {
c.Logger.CloneWithAddedDepth(1).CCriticalf(c.ctx, format, arg...)
}
func (c Context) Fatal(format string, arg ...interface{}) {
c.Logger.CloneWithAddedDepth(1).CFatalf(c.ctx, format, arg...)
}