Skip to content

Commit 885fa14

Browse files
committed
🌱 Add controller.GetLogger
Adds a new GetLogger method required on the controller interface. For folks using controller without managers it's a good way to get a logger pre-filled with information about the controller itself and avoid duplication.r Signed-off-by: Vince Prignano <vincepri@vmware.com>
1 parent e50bc83 commit 885fa14

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pkg/controller/controller.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ type Controller interface {
6868
// Start starts the controller. Start blocks until the context is closed or a
6969
// controller has an error starting.
7070
Start(ctx context.Context) error
71+
72+
// GetLogger returns this controller logger prefilled with basic information.
73+
GetLogger() logr.Logger
7174
}
7275

7376
// New returns a new Controller registered with the Manager. The Manager will ensure that shared Caches have

pkg/internal/controller/controller.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,11 @@ func (c *Controller) reconcileHandler(ctx context.Context, obj interface{}) {
287287
ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, "success").Inc()
288288
}
289289

290+
// GetLogger returns this controller's logger.
291+
func (c *Controller) GetLogger() logr.Logger {
292+
return c.Log
293+
}
294+
290295
// InjectFunc implement SetFields.Injector
291296
func (c *Controller) InjectFunc(f inject.Func) error {
292297
c.SetFields = f

0 commit comments

Comments
 (0)