cluster-api: Index | Files

package log

import ""

Package log mirrors the controller runtime approach to logging, by defining a global logger that defaults to NullLogger.

You can set a custom logger by calling log.SetLogger.

NewLogger returns a clusterctl friendly logr.Logger derived from

The logger is designed to print logs to stdout with a formatting that is easy to read for users but also simple to parse for identifying specific values.

Note: the clusterctl library also support usage of other loggers as long as they conform to the interface.

Following logging conventions are used in clusterctl library:


All messages should start with a capital letter.

Log level:

Use Level 0 (the default, if you don't specify a level) for the most important user feedback only, e.g. - reporting command progress for long running actions - reporting command results when required

Use logging Levels 1 providing more info about the command's internal workflow.

Use logging Levels 5 for for providing all the information required for debug purposes/problem investigation.

Logging WithValues:

Logging WithValues should be preferred to embedding values into log messages because it allows machine readability.

Variables name should start with a capital letter.

Logging WithNames:

Logging WithNames should be used carefully. Please consider that practices like prefixing the logs with something indicating which part of code is generating the log entry might be useful for developers, but it can create confusion for the end users because it increases the verbosity without providing information the user can understand/take benefit from.

Logging errors:

A proper error management should always be preferred to the usage of log.Error.


Package Files

doc.go log.go logger.go util.go


var Log logr.Logger = log.NullLogger{}

Log is the base logger used by kubebuilder. It delegates to another logr.Logger. You *must* call SetLogger to get any actual logging.

func NewLogger Uses

func NewLogger(options ...Option) logr.Logger

NewLogger returns a new instance of the clusterctl.

func SetLogger Uses

func SetLogger(l logr.Logger)

SetLogger sets a concrete logging implementation for all deferred Loggers.

func UnstructuredToValues Uses

func UnstructuredToValues(obj unstructured.Unstructured) []interface{}

UnstructuredToValues provide a utility function for creation values describing an Unstructured objects. e.g. Deployment="capd-controller-manager" Namespace="capd-system" (<Kind>=<name> Namespace=<Namespace>) CustomResourceDefinition="" (omit Namespace if it does not apply)

type Option Uses

type Option func(*logger)

Option is a configuration option supplied to NewLogger

func WithThreshold Uses

func WithThreshold(threshold *int) Option

WithThreshold implements a New Option that allows to set the threshold level for a new logger. The logger will write only log messages with a level/V(x) equal or higher to the threshold.

Package log imports 7 packages (graph) and is imported by 13 packages. Updated 2020-10-14. Refresh now. Tools for package owners.