Documentation ¶
Overview ¶
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:
Message:
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 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.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var Log = logr.New(log.NullLogSink{})
Log is the base logger used by kubebuilder. It delegates to another logr.Logger. You *must* call SetLogger to get any actual logging.
Functions ¶
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).
Types ¶
type Option ¶
type Option func(*logger)
Option is a configuration option supplied to NewLogger.
func WithThreshold ¶
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.