-
Notifications
You must be signed in to change notification settings - Fork 50
/
logging.go
60 lines (43 loc) · 1009 Bytes
/
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
53
54
55
56
57
58
59
60
package tracing
import (
"context"
"time"
"github.com/justtrackio/gosoline/pkg/log"
)
func ContextTraceFieldsResolver(ctx context.Context) map[string]interface{} {
span := GetSpanFromContext(ctx)
if span == nil {
return map[string]interface{}{}
}
traceId := span.GetTrace().GetTraceId()
if traceId == "" {
return map[string]interface{}{}
}
return map[string]interface{}{
"trace_id": span.GetTrace().GetTraceId(),
}
}
type LoggerErrorHandler struct{}
func NewLoggerErrorHandler() *LoggerErrorHandler {
return &LoggerErrorHandler{}
}
func (h *LoggerErrorHandler) Channels() []string {
return []string{}
}
func (h *LoggerErrorHandler) Level() int {
return log.PriorityError
}
func (h *LoggerErrorHandler) Log(_ time.Time, _ int, _ string, _ []interface{}, err error, data log.Data) error {
if err == nil {
return nil
}
if data.Context == nil {
return nil
}
span := GetSpanFromContext(data.Context)
if span == nil {
return nil
}
span.AddError(err)
return nil
}