File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,11 @@ func bad() {
46
46
Str ("bar" , "baz" ).
47
47
Int ("n" , 1 ),
48
48
)
49
+
50
+ // custom object marshaller
51
+ f := & Foo {Bar : & Bar {}}
52
+
53
+ log .Info ().Object ("foo" , f ) // want "must be dispatched by Msg or Send method"
49
54
}
50
55
51
56
func ok () {
@@ -94,4 +99,27 @@ func ok() {
94
99
Str ("bar" , "baz" ).
95
100
Int ("n" , 1 ),
96
101
).Send ()
102
+
103
+ // custom object marshaller
104
+ f := & Foo {Bar : & Bar {}}
105
+
106
+ log .Info ().Object ("foo" , f ).Msg ("" )
107
+ }
108
+
109
+ type Marshaller interface {
110
+ MarshalZerologObject (event * zerolog.Event )
111
+ }
112
+
113
+ type Foo struct {
114
+ Bar Marshaller
115
+ }
116
+
117
+ func (f * Foo ) MarshalZerologObject (event * zerolog.Event ) {
118
+ f .Bar .MarshalZerologObject (event )
119
+ }
120
+
121
+ type Bar struct {}
122
+
123
+ func (b * Bar ) MarshalZerologObject (event * zerolog.Event ) {
124
+ event .Str ("key" , "value" )
97
125
}
Original file line number Diff line number Diff line change @@ -117,7 +117,12 @@ func isZerologEvent(v ssa.Value) bool {
117
117
}
118
118
119
119
func isDispatchMethod (c ssa.CallCommon ) bool {
120
- m := c .StaticCallee ().Name ()
120
+ callee := c .StaticCallee ()
121
+ if callee == nil {
122
+ return false
123
+ }
124
+
125
+ m := callee .Name ()
121
126
if m == "Send" || m == "Msg" || m == "Msgf" || m == "MsgFunc" {
122
127
return true
123
128
}
You can’t perform that action at this time.
0 commit comments