#707·zerolog

Question: should I always use return value of (*Event).Str, (*Event).Uint, etc.?

Author: ratbeknCreated Jan 20, 2025Updated Jan 26, 2026

Hi! Which approach is the right one? 1.

    func (o *Order) foo(e *zerolog.Event) {
        ...
        e.Str(OrderID, o.ID)
        ...
    }

My concern here is that func (e *Event) Str(key, val string) *Event does not explicitly state that e is modified in-place. It only state it adds the field key... and it returns *Event. So this approach based on undocumented behavior of func (e *Event) Str.... Q: Can one day the behavior be changed, therefor this code stop working? 2.

    func (o *Order) foo(e *zerolog.Event) {
        ...
        *e = *(e.Str(OrderID, o.ID))
        ...
    }

This approach is more robust, imo. But less readable. Should one always use this approach?