mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
Fix regression in timestamp resolution
Historic capnslog timestamps are in microsecond resolution. We need to match that when we migrate to the zap logger. Signed-off-by: James Blair <mail@jamesblair.net>
This commit is contained in:
parent
238da4b3f5
commit
b9568dba32
@ -16,6 +16,7 @@ package logutil
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"sort"
|
"sort"
|
||||||
|
"time"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
@ -54,7 +55,12 @@ var DefaultZapLoggerConfig = zap.Config{
|
|||||||
StacktraceKey: "stacktrace",
|
StacktraceKey: "stacktrace",
|
||||||
LineEnding: zapcore.DefaultLineEnding,
|
LineEnding: zapcore.DefaultLineEnding,
|
||||||
EncodeLevel: zapcore.LowercaseLevelEncoder,
|
EncodeLevel: zapcore.LowercaseLevelEncoder,
|
||||||
EncodeTime: zapcore.ISO8601TimeEncoder,
|
|
||||||
|
// Custom EncodeTime function to ensure we match format and precision of historic capnslog timestamps
|
||||||
|
EncodeTime: func(t time.Time, enc zapcore.PrimitiveArrayEncoder) {
|
||||||
|
enc.AppendString(t.Format("2006-01-02T15:04:05.999999Z0700"))
|
||||||
|
},
|
||||||
|
|
||||||
EncodeDuration: zapcore.StringDurationEncoder,
|
EncodeDuration: zapcore.StringDurationEncoder,
|
||||||
EncodeCaller: zapcore.ShortCallerEncoder,
|
EncodeCaller: zapcore.ShortCallerEncoder,
|
||||||
},
|
},
|
||||||
|
@ -56,7 +56,7 @@ func TestServerJsonLogging(t *testing.T) {
|
|||||||
if entry.Timestamp == "" {
|
if entry.Timestamp == "" {
|
||||||
t.Errorf(`Missing "ts" key, line: %s`, line)
|
t.Errorf(`Missing "ts" key, line: %s`, line)
|
||||||
}
|
}
|
||||||
if _, err := time.Parse("2006-01-02T15:04:05.000Z0700", entry.Timestamp); entry.Timestamp != "" && err != nil {
|
if _, err := time.Parse("2006-01-02T15:04:05.999999Z0700", entry.Timestamp); entry.Timestamp != "" && err != nil {
|
||||||
t.Errorf(`Unexpected "ts" key format, err: %s`, err)
|
t.Errorf(`Unexpected "ts" key format, err: %s`, err)
|
||||||
}
|
}
|
||||||
if entry.Caller == "" {
|
if entry.Caller == "" {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user