diff --git a/pkg/logger/zap.go b/pkg/logger/zap.go index 10d6fd465..5e6f68c10 100644 --- a/pkg/logger/zap.go +++ b/pkg/logger/zap.go @@ -1,6 +1,7 @@ package logger import ( + "github.com/go-logr/logr" "github.com/go-logr/zapr" "go.uber.org/zap" "go.uber.org/zap/zapcore" @@ -33,10 +34,14 @@ func CoreZapLogger() *zap.Logger { internalZapLogger, _ = internalZapConfig.Build() } // set the controller-runtime logger with the current zap logger - ctrl.SetLogger(zapr.NewLoggerWithOptions(internalZapLogger)) + ctrl.SetLogger(zapr.NewLogger(internalZapLogger)) return internalZapLogger } +func ZaprLogger() logr.Logger { + return zapr.NewLogger(internalZapLogger) +} + // DefaultZapLogger is a sugar wraps the Logger to provide a more ergonomic, but slightly slower, API func DefaultZapLogger() *zap.SugaredLogger { logger := CoreZapLogger() diff --git a/pkg/transport/controller/controller.go b/pkg/transport/controller/controller.go index d626044f6..58e430a29 100644 --- a/pkg/transport/controller/controller.go +++ b/pkg/transport/controller/controller.go @@ -8,13 +8,13 @@ import ( corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/klog/v2" ctrl "sigs.k8s.io/controller-runtime" "sigs.k8s.io/controller-runtime/pkg/builder" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/event" "sigs.k8s.io/controller-runtime/pkg/predicate" + "github.com/stolostron/multicluster-global-hub/pkg/logger" "github.com/stolostron/multicluster-global-hub/pkg/transport" "github.com/stolostron/multicluster-global-hub/pkg/transport/config" "github.com/stolostron/multicluster-global-hub/pkg/transport/consumer" @@ -23,6 +23,8 @@ import ( "github.com/stolostron/multicluster-global-hub/pkg/utils" ) +var log = logger.DefaultZapLogger() + type TransportCallback func(transportClient transport.TransportClient) error type TransportCtrl struct { @@ -169,7 +171,7 @@ func (c *TransportCtrl) ReconcileConsumer(ctx context.Context) error { } go func() { if err = receiver.Start(ctx); err != nil { - klog.Errorf("failed to start the consumser: %v", err) + log.Errorf("failed to start the consumser: %v", err) } }() c.transportClient.consumer = receiver @@ -178,7 +180,6 @@ func (c *TransportCtrl) ReconcileConsumer(ctx context.Context) error { return fmt.Errorf("failed to reconnect the consumer: %w", err) } } - klog.Info("the transport(kafka) consumer is created/updated") return nil }