Skip to content

Commit

Permalink
🌱 Add controller.GetLogger
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
vincepri committed Oct 2, 2020
1 parent e50bc83 commit 885fa14
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ type Controller interface {
// Start starts the controller. Start blocks until the context is closed or a
// controller has an error starting.
Start(ctx context.Context) error

// GetLogger returns this controller logger prefilled with basic information.
GetLogger() logr.Logger
}

// New returns a new Controller registered with the Manager. The Manager will ensure that shared Caches have
Expand Down
5 changes: 5 additions & 0 deletions pkg/internal/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@ func (c *Controller) reconcileHandler(ctx context.Context, obj interface{}) {
ctrlmetrics.ReconcileTotal.WithLabelValues(c.Name, "success").Inc()
}

// GetLogger returns this controller's logger.
func (c *Controller) GetLogger() logr.Logger {
return c.Log
}

// InjectFunc implement SetFields.Injector
func (c *Controller) InjectFunc(f inject.Func) error {
c.SetFields = f
Expand Down

0 comments on commit 885fa14

Please sign in to comment.