From 70ada993b3ca7435565593c0a581d9574f8c2ea5 Mon Sep 17 00:00:00 2001 From: Andreas Sommer Date: Mon, 6 Nov 2023 17:40:45 +0100 Subject: [PATCH] Pass logger to machine pool scope to get verbosity right, fix copying logger in `With...` methods --- exp/controllers/awsmachinepool_controller.go | 1 + pkg/logger/logger.go | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/exp/controllers/awsmachinepool_controller.go b/exp/controllers/awsmachinepool_controller.go index a3b2926480..e35f746a39 100644 --- a/exp/controllers/awsmachinepool_controller.go +++ b/exp/controllers/awsmachinepool_controller.go @@ -131,6 +131,7 @@ func (r *AWSMachinePoolReconciler) Reconcile(ctx context.Context, req ctrl.Reque // Create the machine pool scope machinePoolScope, err := scope.NewMachinePoolScope(scope.MachinePoolScopeParams{ Client: r.Client, + Logger: log, Cluster: cluster, MachinePool: machinePool, InfraCluster: infraCluster, diff --git a/pkg/logger/logger.go b/pkg/logger/logger.go index c836553e54..c2cd0ebde2 100644 --- a/pkg/logger/logger.go +++ b/pkg/logger/logger.go @@ -99,11 +99,15 @@ func (c *Logger) GetLogger() logr.Logger { } func (c *Logger) WithValues(keysAndValues ...any) *Logger { - c.logger = c.logger.WithValues(keysAndValues...) - return c + return &Logger{ + callStackHelper: c.callStackHelper, + logger: c.logger.WithValues(keysAndValues...), + } } func (c *Logger) WithName(name string) *Logger { - c.logger = c.logger.WithName(name) - return c + return &Logger{ + callStackHelper: c.callStackHelper, + logger: c.logger.WithName(name), + } }