-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
38 lines (33 loc) · 1.39 KB
/
options.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
// #############################################################################
// # File: options.go #
// # Project: zlog #
// # Created Date: 2024/11/21 17:15:14 #
// # Author: realjf #
// # ----- #
// # Last Modified: 2024/11/21 17:47:48 #
// # Modified By: realjf #
// # ----- #
// # #
// #############################################################################
package zlog
import (
"context"
"github.com/realjf/zlog/trace"
"go.uber.org/zap"
)
type Option func(*zLog) (*zLog, error)
func WithTrace(ctx context.Context) Option {
return func(z *zLog) (*zLog, error) {
if tc, ok := trace.FromContext(ctx); ok {
logger := z.logger.With(
zap.String("traceID", tc.TraceID),
zap.String("spanID", tc.SpanID),
zap.String("parentSpanID", tc.ParentSpanID),
)
newZlog := newZLog(z.cfg, z.options...)
newZlog.logger = logger
return newZlog, nil
}
return z, nil
}
}