/
field.go
78 lines (63 loc) · 1.72 KB
/
field.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package log
import (
"context"
"github.com/alphadose/haxmap"
)
// Fields is a wrapper for zerolog.Entry
// we need to insert some sentry captures here
type Fields struct {
kv *haxmap.Map[string, any]
}
// WithFunc is short for WithField
func WithFunc(fname string) *Fields {
return WithField("func", fname)
}
// WithField add kv into log entry
func WithField(key string, value any) *Fields {
r := haxmap.New[string, any]()
r.Set(key, value)
return &Fields{
kv: r,
}
}
// WithField .
func (f *Fields) WithField(key string, value any) *Fields {
f.kv.Set(key, value)
return f
}
// Fatalf forwards to sentry
func (f Fields) Fatalf(ctx context.Context, err error, format string, args ...any) {
fatalf(ctx, err, format, f.kv, args...)
}
// Warnf is Warnf
func (f Fields) Warnf(ctx context.Context, format string, args ...any) {
warnf(ctx, format, f.kv, args...)
}
// Warn is Warn
func (f Fields) Warn(ctx context.Context, args ...any) {
f.Warnf(ctx, "%+v", args...)
}
// Infof is Infof
func (f Fields) Infof(ctx context.Context, format string, args ...any) {
infof(ctx, format, f.kv, args...)
}
// Info is Info
func (f Fields) Info(ctx context.Context, args ...any) {
f.Infof(ctx, "%+v", args...)
}
// Debugf is Debugf
func (f Fields) Debugf(ctx context.Context, format string, args ...any) {
debugf(ctx, format, f.kv, args...)
}
// Debug is Debug
func (f Fields) Debug(ctx context.Context, args ...any) {
f.Debugf(ctx, "%+v", args...)
}
// Errorf forwards to sentry
func (f Fields) Errorf(ctx context.Context, err error, format string, args ...any) {
errorf(ctx, err, format, f.kv, args...)
}
// Error forwards to sentry
func (f Fields) Error(ctx context.Context, err error, args ...any) {
f.Errorf(ctx, err, "%+v", args...)
}