@@ -3,37 +3,44 @@ package log
3
3
import (
4
4
"context"
5
5
6
+ "github.com/alphadose/haxmap"
6
7
"github.com/getsentry/sentry-go"
8
+ "github.com/rs/zerolog"
7
9
)
8
10
9
- func fatalf (ctx context.Context , err error , format string , fields map [string ] interface {}, args ... interface {}) {
11
+ func fatalf (ctx context.Context , err error , format string , fields * haxmap. Map [string , interface {}] , args ... interface {}) {
10
12
args = argsValidate (args )
11
13
reportToSentry (ctx , sentry .LevelFatal , err , format , args ... )
12
- globalLogger .Fatal ().Fields (fields ).Err (err ).Msgf (format , args ... )
14
+ f := globalLogger .Fatal ()
15
+ wrap (f , fields ).Err (err ).Msgf (format , args ... )
13
16
}
14
17
15
- func warnf (_ context.Context , format string , fields map [string ] interface {}, args ... interface {}) {
18
+ func warnf (_ context.Context , format string , fields * haxmap. Map [string , interface {}] , args ... interface {}) {
16
19
args = argsValidate (args )
17
- globalLogger .Warn ().Fields (fields ).Msgf (format , args ... )
20
+ f := globalLogger .Warn ()
21
+ wrap (f , fields ).Msgf (format , args ... )
18
22
}
19
23
20
- func infof (_ context.Context , format string , fields map [string ] interface {}, args ... interface {}) {
24
+ func infof (_ context.Context , format string , fields * haxmap. Map [string , interface {}] , args ... interface {}) {
21
25
args = argsValidate (args )
22
- globalLogger .Info ().Fields (fields ).Msgf (format , args ... )
26
+ f := globalLogger .Info ()
27
+ wrap (f , fields ).Msgf (format , args ... )
23
28
}
24
29
25
- func debugf (_ context.Context , format string , fields map [string ] interface {}, args ... interface {}) {
30
+ func debugf (_ context.Context , format string , fields * haxmap. Map [string , interface {}] , args ... interface {}) {
26
31
args = argsValidate (args )
27
- globalLogger .Debug ().Fields (fields ).Msgf (format , args ... )
32
+ f := globalLogger .Debug ()
33
+ wrap (f , fields ).Msgf (format , args ... )
28
34
}
29
35
30
- func errorf (ctx context.Context , err error , format string , fields map [string ] interface {}, args ... interface {}) {
36
+ func errorf (ctx context.Context , err error , format string , fields * haxmap. Map [string , interface {}] , args ... interface {}) {
31
37
if err == nil {
32
38
return
33
39
}
34
40
args = argsValidate (args )
35
41
reportToSentry (ctx , sentry .LevelError , err , format , args ... )
36
- globalLogger .Error ().Fields (fields ).Stack ().Err (err ).Msgf (format , args ... )
42
+ f := globalLogger .Error ()
43
+ wrap (f , fields ).Stack ().Err (err ).Msgf (format , args ... )
37
44
}
38
45
39
46
func argsValidate (args []interface {}) []interface {} {
@@ -42,3 +49,14 @@ func argsValidate(args []interface{}) []interface{} {
42
49
}
43
50
return []interface {}{"" }
44
51
}
52
+
53
+ func wrap (f * zerolog.Event , kv * haxmap.Map [string , interface {}]) * zerolog.Event {
54
+ if kv == nil {
55
+ return f
56
+ }
57
+ kv .ForEach (func (k string , v interface {}) bool {
58
+ f = f .Interface (k , v )
59
+ return true
60
+ })
61
+ return f
62
+ }
0 commit comments