uber-go/zap

Proposal: Add an "always encode numbers as strings" option to zapcore.EncoderConfig

fishy opened this issue · 0 comments

fishy commented

The reason of this proposal is that in json the only number format defined is float64. so int64 numbers in json log might lose precision from the log ingestion. Take this log line as an example:

{"level":"DEBUG","timestamp":"2020-11-24T20:50:50.393889219Z","caller":"testing/testing.go:1123","message":"test int64","int64":955216105955032459,"int64-field":955216105955032459}

The log ingestion vendor we use doesn't do any special handling on json numbers, so the int64 numbers becomes 955216105955032400 in their UI.

The proposal is to add an option to encode them automatically into:

{"level":"DEBUG","timestamp":"2020-11-24T20:50:50.393889219Z","caller":"testing/testing.go:1123","message":"test int64","int64":"955216105955032459","int64-field":"955216105955032459"}