Skip to content

Commit 64fd014

Browse files
authored
feat: make logger encoders kube-aware
Signed-off-by: GitHub <[email protected]>
1 parent faa9c44 commit 64fd014

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

cns/logger/v2/cores/etw_windows.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"github.com/pkg/errors"
88
"go.uber.org/zap"
99
"go.uber.org/zap/zapcore"
10+
ctrlzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
1011
)
1112

1213
type ETWConfig struct {
@@ -44,5 +45,5 @@ func ETWCore(cfg *ETWConfig) (zapcore.Core, func(), error) {
4445
encoderConfig := zap.NewProductionEncoderConfig()
4546
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
4647
jsonEncoder := zapcore.NewJSONEncoder(encoderConfig)
47-
return zapetw.New(cfg.ProviderName, cfg.EventName, jsonEncoder, cfg.level) //nolint:wrapcheck // ignore
48+
return zapetw.New(cfg.ProviderName, cfg.EventName, &ctrlzap.KubeAwareEncoder{Encoder: jsonEncoder}, cfg.level) //nolint:wrapcheck // ignore
4849
}

cns/logger/v2/cores/file.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"go.uber.org/zap"
88
"go.uber.org/zap/zapcore"
99
"gopkg.in/natefinch/lumberjack.v2"
10+
ctrlzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
1011
)
1112

1213
type FileConfig struct {
@@ -50,5 +51,5 @@ func FileCore(cfg *FileConfig) (zapcore.Core, func(), error) {
5051
encoderConfig := zap.NewProductionEncoderConfig()
5152
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
5253
jsonEncoder := zapcore.NewJSONEncoder(encoderConfig)
53-
return zapcore.NewCore(jsonEncoder, zapcore.AddSync(filesink), cfg.level), func() { _ = filesink.Close() }, nil
54+
return zapcore.NewCore(&ctrlzap.KubeAwareEncoder{Encoder: jsonEncoder}, zapcore.AddSync(filesink), cfg.level), func() { _ = filesink.Close() }, nil
5455
}

cns/logger/v2/cores/stdout.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"github.com/pkg/errors"
99
"go.uber.org/zap"
1010
"go.uber.org/zap/zapcore"
11+
ctrlzap "sigs.k8s.io/controller-runtime/pkg/log/zap"
1112
)
1213

1314
type StdoutConfig struct {
@@ -41,5 +42,5 @@ func (cfg *StdoutConfig) UnmarshalJSON(data []byte) error {
4142
func StdoutCore(l zapcore.Level) zapcore.Core {
4243
encoderConfig := zap.NewProductionEncoderConfig()
4344
encoderConfig.EncodeTime = zapcore.ISO8601TimeEncoder
44-
return zapcore.NewCore(logfmt.NewEncoder(encoderConfig), os.Stdout, l)
45+
return zapcore.NewCore(&ctrlzap.KubeAwareEncoder{Encoder: logfmt.NewEncoder(encoderConfig)}, os.Stdout, l)
4546
}

0 commit comments

Comments
 (0)