-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Pointer to T Field constructors. #753
Comments
Would we want to report |
zap should report To make up user requirements to take this argument a step further, if for some reason a consumer of these zap logs enforced a schema during ingestion silently dropping the key within the logging library could have adverse effects to the rest of the message. |
Makes sense. In that case, it's just a matter of deciding a convention. Initial proposal:
We'll only want to do it for primitives, not interfaces, so Thoughts? @jcorbin @prashantv @dnathe4th @twilly |
I'm fine with adding pointer methods for primitives. I think using We might want to add a special-case for |
@abhinav -- I took a shot at feeling my way through this. LMK if this sketch seems like the right approach and if so I can try and finish it out and submit a proper pull request. |
Thanks for the feedback. Will put up a pull request with what I came with. Also for posterity, leaving a note here that, if we want to go further and be less hacky than packing type AddNiller interface {
AddNil(key string)
} have the JSON Encoder implement it, and then document that marshaler implementations that are performance sensitive can check whether the encoder they receive implements |
RE: ^: I just realized that we'll still have to smuggle the |
Right -- The |
This adds support for building fields from pointers to primitive types we already accept. These new field constructors accept and handle `nil` values in addition to the non-nil primitive values. For nil values, we fall back to the behavior of `zap.Reflect(..)`, which we optimize for in the JSON encoder so that we don't use `encoding/json` just to build the string `"null"`. Resolves #753
This adds support for building fields from pointers to primitive types we already accept. These new field constructors accept and handle `nil` values in addition to the non-nil primitive values. For nil values, we fall back to the behavior of `zap.Reflect(..)`, which we optimize for in the JSON encoder so that we don't use `encoding/json` just to build the string `"null"`. Resolves uber-go#753
Zap has support for constructing Field from primitive types but doesn't have constructors for pointers to the primitive types (
*bool
,*int
, etc). These types are encountered often enough that constructing through Reflect is not ideal.Let's discuss this feature.
The text was updated successfully, but these errors were encountered: