-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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 display of zap.Time field with zero time struct #737
Comments
Storing a Since zap is focused on performance, we made the choice to avoid allocations here. I think we have a couple of options to fix this though:
|
Of course, storing in
I think storing a special string makes sense. I'm not sure this requires a new field type as the added cost would be very low if you're in the int64 range. |
After thinking about this more, I think it might actually be cleaner to just have 2 types of time fields:
The latter type should only be used if the field cannot be stored as an |
Fixes #737, #803. Time values are encoded by storing the UnixNano representation, but this fails when the value of UnixNano is out of int64 range, see docs: https://golang.org/pkg/time/#Time.UnixNano > The result is undefined if the Unix time in nanoseconds cannot be represented by an int64 (a date before the year 1678 or after 2262) Fix this by storing values outside of UnixNano range as-is rather than using UnixNano with a new Field type.
Fixes #737, #803. Time values are encoded by storing the UnixNano representation, but this fails when the value of UnixNano is out of int64 range, see docs: https://golang.org/pkg/time/#Time.UnixNano > The result is undefined if the Unix time in nanoseconds cannot be represented by an int64 (a date before the year 1678 or after 2262) Fix this by storing values outside of UnixNano range as-is rather than using UnixNano with a new Field type.
Fixes uber-go#737, uber-go#803. Time values are encoded by storing the UnixNano representation, but this fails when the value of UnixNano is out of int64 range, see docs: https://golang.org/pkg/time/#Time.UnixNano > The result is undefined if the Unix time in nanoseconds cannot be represented by an int64 (a date before the year 1678 or after 2262) Fix this by storing values outside of UnixNano range as-is rather than using UnixNano with a new Field type.
Fixes uber-go#737, uber-go#803. Time values are encoded by storing the UnixNano representation, but this fails when the value of UnixNano is out of int64 range, see docs: https://golang.org/pkg/time/#Time.UnixNano > The result is undefined if the Unix time in nanoseconds cannot be represented by an int64 (a date before the year 1678 or after 2262) Fix this by storing values outside of UnixNano range as-is rather than using UnixNano with a new Field type.
When logging a zero initialized time.Time struct the output is not consistent:
Will output the time:
1754-08-30T22:43:41.128654848Z
because callingUnixNano()
thenUnix(0, nsec)
is not symetric in this case.The correct output would be
0001-01-01 00:00:00 +0000 UTC
(with the same layout as above).see https://gist.github.com/patdowney/b64a4fee790ac66dd1a2 that exhibit the issue.
Looking at zap.Time I was wondering why you don't pass the Time struct in the Interface field instead of converting to an integer. Maybe this is to avoid making a new reference to traverse for the GC ?
zap/field.go
Lines 180 to 184 in 4252145
zap/zapcore/field.go
Lines 141 to 147 in badef73
The text was updated successfully, but these errors were encountered: