Merge pull request #100013 from rphillips/fixes/add_duration_encoder

add duration encoder to structured logger
This commit is contained in:
Kubernetes Prow Robot 2021-03-09 17:39:32 -08:00 committed by GitHub
commit db978e0480
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -148,8 +148,9 @@ func (l *zapLogger) WithName(name string) logr.Logger {
var encoderConfig = zapcore.EncoderConfig{
MessageKey: "msg",
TimeKey: "ts",
EncodeTime: zapcore.EpochMillisTimeEncoder,
TimeKey: "ts",
EncodeTime: zapcore.EpochMillisTimeEncoder,
EncodeDuration: zapcore.StringDurationEncoder,
}
// NewJSONLogger creates a new json logr.Logger using the given Zap Logger to log.

View File

@ -57,6 +57,11 @@ func TestZapLoggerInfo(t *testing.T) {
format: "{\"ts\":%f,\"msg\":\"non-string key argument passed to logging, ignoring all later arguments\",\"v\":0}\n{\"ts\":0.000123,\"msg\":\"test for non-string key argument\",\"v\":0,\"ns\":\"default\",\"podnum\":2}\n",
keysValues: []interface{}{"ns", "default", "podnum", 2, 200, "replica", "Running", 10},
},
{
msg: "test for duration value argument",
format: "{\"ts\":%f,\"msg\":\"test for duration value argument\",\"v\":0,\"duration\":\"5s\"}\n",
keysValues: []interface{}{"duration", time.Duration(5 * time.Second)},
},
}
for _, data := range testDataInfo {