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

inconsistent semantics on type "Logger" #563

Open
mrkagelui opened this issue Jul 6, 2023 · 3 comments
Open

inconsistent semantics on type "Logger" #563

mrkagelui opened this issue Jul 6, 2023 · 3 comments

Comments

@mrkagelui
Copy link

Hi, currently Logger uses a mix of value and pointer semantics, e.g., WithContext has a value receiver, Fatal, Err etc have pointer receivers, why is this? sorry if this has been brought up before

@nikicat
Copy link

nikicat commented Jul 30, 2023

I'm very curious too. Pointer receivers prevent me from using zerolog.Logger objects returned from a function call.

@mitar
Copy link
Contributor

mitar commented Aug 18, 2023

In general in Go, pointer receivers are used when you want to modify the struct inside the method, and value receiver when you do not do so (or, you return a copy). I think zerolog is pretty consistent in using one or the other so that it does not needlessly use pointer receivers when they are not really needed.

I am not sure how is this preventing anyone from returning objects from function calls? With zerolog you do have to be mindful when you are making a copy of the struct and when you are modifying struct in-place. Are you talking about that?

@mitar
Copy link
Contributor

mitar commented Aug 18, 2023

I think this is a duplicate of #400 anyway.

Also FAQ on this topic. It does recommend having consistency here in having all methods use pointer receivers. I think this is a bit of historical thing with zerolog while its API developed.

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

3 participants