Skip to content

Commit

Permalink
log remove klog
Browse files Browse the repository at this point in the history
Signed-off-by: myan <[email protected]>
  • Loading branch information
yanmxa committed Oct 29, 2024
1 parent 5e40e07 commit 02c0c1b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
7 changes: 6 additions & 1 deletion pkg/logger/zap.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 4 additions & 3 deletions pkg/transport/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
}

Expand Down

0 comments on commit 02c0c1b

Please sign in to comment.