9
9
"github.com/opentracing/opentracing-go/ext"
10
10
otlog "github.com/opentracing/opentracing-go/log"
11
11
12
- "github.com/cortexproject/cortex/pkg/tenant "
13
- util_log "github.com/cortexproject/cortex/pkg/util/log "
12
+ "github.com/grafana/dskit/dslog "
13
+ "github.com/grafana/dskit/tenant "
14
14
)
15
15
16
16
type loggerCtxMarker struct {}
@@ -29,44 +29,31 @@ type SpanLogger struct {
29
29
opentracing.Span
30
30
}
31
31
32
- // New makes a new SpanLogger, where logs will be sent to the global logger.
33
- func New (ctx context.Context , method string , kvps ... interface {}) (* SpanLogger , context.Context ) {
34
- return NewWithLogger (ctx , util_log .Logger , method , kvps ... )
35
- }
36
-
37
- // NewWithLogger makes a new SpanLogger with a custom log.Logger to send logs
32
+ // New makes a new SpanLogger with a custom log.Logger to send logs
38
33
// to. The provided context will have the logger attached to it and can be
39
34
// retrieved with FromContext or FromContextWithFallback.
40
- func NewWithLogger (ctx context.Context , l log.Logger , method string , kvps ... interface {}) (* SpanLogger , context.Context ) {
35
+ func New (ctx context.Context , logger log.Logger , method string , kvps ... interface {}) (* SpanLogger , context.Context ) {
41
36
span , ctx := opentracing .StartSpanFromContext (ctx , method )
42
- if ids , _ := tenant .TenantIDs (ctx ); len (ids ) > 0 {
37
+ if ids , _ := tenant .IDs (ctx ); len (ids ) > 0 {
43
38
span .SetTag (TenantIDTagName , ids )
44
39
}
45
- logger := & SpanLogger {
46
- Logger : log .With (util_log .WithContext (ctx , l ), "method" , method ),
40
+ l := & SpanLogger {
41
+ Logger : log .With (dslog .WithContext (ctx , logger ), "method" , method ),
47
42
Span : span ,
48
43
}
49
44
if len (kvps ) > 0 {
50
- level .Debug (logger ).Log (kvps ... )
45
+ level .Debug (l ).Log (kvps ... )
51
46
}
52
47
53
48
ctx = context .WithValue (ctx , loggerCtxKey , l )
54
- return logger , ctx
55
- }
56
-
57
- // FromContext returns a span logger using the current parent span. If there
58
- // is no parent span, the SpanLogger will only log to the logger
59
- // in the context. If the context doesn't have a logger, the global logger
60
- // is used.
61
- func FromContext (ctx context.Context ) * SpanLogger {
62
- return FromContextWithFallback (ctx , util_log .Logger )
49
+ return l , ctx
63
50
}
64
51
65
- // FromContextWithFallback returns a span logger using the current parent span.
66
- // IF there is no parent span, the SpanLogger will only log to the logger
52
+ // FromContext returns a span logger using the current parent span.
53
+ // If there is no parent span, the SpanLogger will only log to the logger
67
54
// within the context. If the context doesn't have a logger, the fallback
68
55
// logger is used.
69
- func FromContextWithFallback (ctx context.Context , fallback log.Logger ) * SpanLogger {
56
+ func FromContext (ctx context.Context , fallback log.Logger ) * SpanLogger {
70
57
logger , ok := ctx .Value (loggerCtxKey ).(log.Logger )
71
58
if ! ok {
72
59
logger = fallback
@@ -76,7 +63,7 @@ func FromContextWithFallback(ctx context.Context, fallback log.Logger) *SpanLogg
76
63
sp = defaultNoopSpan
77
64
}
78
65
return & SpanLogger {
79
- Logger : util_log .WithContext (ctx , logger ),
66
+ Logger : dslog .WithContext (ctx , logger ),
80
67
Span : sp ,
81
68
}
82
69
}
@@ -93,7 +80,7 @@ func (s *SpanLogger) Log(kvps ...interface{}) error {
93
80
return nil
94
81
}
95
82
96
- // Error sets error flag and logs the error on the span, if non-nil. Returns the err passed in.
83
+ // Error sets error flag and logs the error on the span, if non-nil. Returns the err passed in.
97
84
func (s * SpanLogger ) Error (err error ) error {
98
85
if err == nil {
99
86
return nil
0 commit comments