File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -3,12 +3,13 @@ package hlog
3
3
import (
4
4
"context"
5
5
"fmt"
6
- "github.com/natefinch/lumberjack"
7
- "go.uber.org/zap"
8
- "go.uber.org/zap/zapcore"
9
6
"os"
10
7
"strings"
11
8
"sync"
9
+
10
+ "github.com/natefinch/lumberjack"
11
+ "go.uber.org/zap"
12
+ "go.uber.org/zap/zapcore"
12
13
)
13
14
14
15
var (
@@ -52,6 +53,14 @@ func (l *Logger) GetCtx(ctx context.Context) *zap.Logger {
52
53
return l .Logger
53
54
}
54
55
56
+ func (l * Logger ) WithContext (ctx context.Context ) * zap.Logger {
57
+ log , ok := ctx .Value (l .opts .CtxKey ).(* zap.Logger )
58
+ if ok {
59
+ return log
60
+ }
61
+ return l .Logger
62
+ }
63
+
55
64
func (l * Logger ) AddCtx (ctx context.Context , field ... zap.Field ) (context.Context , * zap.Logger ) {
56
65
log := l .With (field ... )
57
66
ctx = context .WithValue (ctx , l .opts .CtxKey , log )
You can’t perform that action at this time.
0 commit comments