Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
ratbekn opened this issue Jan 20, 2025 · 0 comments

Comments

@ratbekn
Copy link

ratbekn commented Jan 20, 2025

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant