mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-27 13:15:36 +00:00
json: enable WithName logging
The name added to a logger via WithName only gets printed when a key is chosen. "logger" is used as in the zap examples. This becomes relevant once we support contextual logging. When logging through klog the name is always empty.
This commit is contained in:
@@ -43,6 +43,7 @@ func NewJSONLogger(infoStream, errorStream zapcore.WriteSyncer, encoderConfig *z
|
|||||||
encoderConfig = &zapcore.EncoderConfig{
|
encoderConfig = &zapcore.EncoderConfig{
|
||||||
MessageKey: "msg",
|
MessageKey: "msg",
|
||||||
CallerKey: "caller",
|
CallerKey: "caller",
|
||||||
|
NameKey: "logger",
|
||||||
TimeKey: "ts",
|
TimeKey: "ts",
|
||||||
EncodeTime: epochMillisTimeEncoder,
|
EncodeTime: epochMillisTimeEncoder,
|
||||||
EncodeDuration: zapcore.StringDurationEncoder,
|
EncodeDuration: zapcore.StringDurationEncoder,
|
||||||
|
@@ -61,10 +61,9 @@ func TestZapLoggerInfo(t *testing.T) {
|
|||||||
keysValues: []interface{}{"duration", time.Duration(5 * time.Second)},
|
keysValues: []interface{}{"duration", time.Duration(5 * time.Second)},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
msg: "test for WithName",
|
msg: "test for WithName",
|
||||||
names: []string{"hello", "world"},
|
names: []string{"hello", "world"},
|
||||||
// TODO: log names
|
format: "{\"ts\":%f,\"logger\":\"hello.world\",\"caller\":\"json/json_test.go:%d\",\"msg\":\"test for WithName\",\"v\":0}\n",
|
||||||
format: "{\"ts\":%f,\"caller\":\"json/json_test.go:%d\",\"msg\":\"test for WithName\",\"v\":0}\n",
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user