Version: v1.0.0 Latest Latest

This package is not in the latest version of its module.

Go to latest
Published: Oct 6, 2021 License: Apache-2.0 Imports: 7 Imported by: 10



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 https://git.k8s.io/klog/klogr/klogr.go.

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 github.com/go-logr/logr.Logger 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.



This section is empty.


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

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

NewLogger returns a new instance of the clusterctl.

func SetLogger

func SetLogger(l logr.Logger)

SetLogger sets a concrete logging implementation for all deferred Loggers.

func UnstructuredToValues

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="dockerclusters.infrastructure.cluster.x-k8s.io" (omit Namespace if it does not apply).


type Option

type Option func(*logger)

Option is a configuration option supplied to NewLogger.

func WithThreshold

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL