mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +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:
parent
3fe5b3e09d
commit
ab318cf89f
@ -43,6 +43,7 @@ func NewJSONLogger(infoStream, errorStream zapcore.WriteSyncer, encoderConfig *z
|
||||
encoderConfig = &zapcore.EncoderConfig{
|
||||
MessageKey: "msg",
|
||||
CallerKey: "caller",
|
||||
NameKey: "logger",
|
||||
TimeKey: "ts",
|
||||
EncodeTime: epochMillisTimeEncoder,
|
||||
EncodeDuration: zapcore.StringDurationEncoder,
|
||||
|
@ -61,10 +61,9 @@ func TestZapLoggerInfo(t *testing.T) {
|
||||
keysValues: []interface{}{"duration", time.Duration(5 * time.Second)},
|
||||
},
|
||||
{
|
||||
msg: "test for WithName",
|
||||
names: []string{"hello", "world"},
|
||||
// TODO: log names
|
||||
format: "{\"ts\":%f,\"caller\":\"json/json_test.go:%d\",\"msg\":\"test for WithName\",\"v\":0}\n",
|
||||
msg: "test for WithName",
|
||||
names: []string{"hello", "world"},
|
||||
format: "{\"ts\":%f,\"logger\":\"hello.world\",\"caller\":\"json/json_test.go:%d\",\"msg\":\"test for WithName\",\"v\":0}\n",
|
||||
},
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user