Skip to content

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

Open
@ratbekn

Description

@ratbekn

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions