Documentation ¶
Index ¶
- func InitFlags(flagset *flag.FlagSet)
- func NewContext(ctx context.Context, log Logger) context.Context
- func NewContextWithDiscard(ctx context.Context) context.Context
- func PreventKeyConflicts(log logr.Logger) logr.Logger
- func SetLogger(log Logger)
- type Config
- func (c *Config) SetDisableCaller(zapCfg *zap.Config)
- func (c *Config) SetDisableStacktrace(zapCfg *zap.Config)
- func (c *Config) SetLogFormat(zapCfg *zap.Config)
- func (c *Config) SetLogLevel(zapCfg *zap.Config)
- func (c *Config) SetTimestamp(zapCfg *zap.Config)
- func (c *Config) WithLogFormat(f LogFormat) *Config
- func (c *Config) WithLogLevel(l LogLevel) *Config
- type KeyConflictPreventionLayer
- func (kcpl KeyConflictPreventionLayer) Enabled(level int) bool
- func (kcpl KeyConflictPreventionLayer) Error(err error, msg string, keysAndValues ...interface{})
- func (kcpl KeyConflictPreventionLayer) Info(level int, msg string, keysAndValues ...interface{})
- func (kcpl KeyConflictPreventionLayer) Init(info logr.RuntimeInfo)
- func (kcpl KeyConflictPreventionLayer) WithName(name string) logr.LogSink
- func (kcpl KeyConflictPreventionLayer) WithValues(keysAndValues ...interface{}) logr.LogSink
- type LogFormat
- type LogLevel
- type Logger
- func Discard() Logger
- func FromContext(ctx context.Context) (Logger, error)
- func FromContextOrDiscard(ctx context.Context) Logger
- func FromContextOrNew(ctx context.Context, keysAndValuesFallback []interface{}, ...) (Logger, context.Context)
- func FromContextOrPanic(ctx context.Context) Logger
- func FromContextWithFallback(ctx context.Context, fallback Logger, keysAndValues ...interface{}) (Logger, context.Context)
- func GetLogger() (Logger, error)
- func MustStartReconcileFromContext(ctx context.Context, req reconcile.Request, ...) (Logger, context.Context)
- func New(config *Config) (Logger, error)
- func NewCliLogger() (Logger, error)
- func StartReconcileFromContext(ctx context.Context, req reconcile.Request) (Logger, context.Context, error)
- func Wrap(log logr.Logger) Logger
- func (l Logger) Debug(msg string, keysAndValues ...interface{})
- func (l Logger) Enabled(lvl LogLevel) bool
- func (l Logger) Error(err error, msg string, keysAndValues ...interface{})
- func (l Logger) Info(msg string, keysAndValues ...interface{})
- func (l Logger) IsInitialized() bool
- func (l Logger) Log(lvl LogLevel, msg string, keysAndValues ...interface{})
- func (l Logger) Logr() logr.Logger
- func (l Logger) Reconciles(name, reconciledResource string) Logger
- func (l Logger) StartReconcile(req reconcile.Request, keysAndValues ...interface{}) Logger
- func (l Logger) StartReconcileAndAddToContext(ctx context.Context, req reconcile.Request, keysAndValues ...interface{}) (Logger, context.Context)
- func (l Logger) WithName(name string) Logger
- func (l Logger) WithNameAndContext(ctx context.Context, name string) (Logger, context.Context)
- func (l Logger) WithValues(keysAndValues ...interface{}) Logger
- func (l Logger) WithValuesAndContext(ctx context.Context, keysAndValues ...interface{}) (Logger, context.Context)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewContext ¶
NewContext is a wrapper for logr.NewContext.
func NewContextWithDiscard ¶
NewContextWithDiscard adds a discard logger to the given context and returns the new context.
func PreventKeyConflicts ¶
PreventKeyConflicts takes a logr.Logger and wraps a KeyConflictPreventionLayer around its LogSink. It is already used by the logging framework's constructors and will likely not have to be called from outside the package. Mainly exported for testing purposes.
Types ¶
type Config ¶
type Config struct { Development bool Cli bool DisableStacktrace bool DisableCaller bool DisableTimestamp bool Level logLevelValue Format logFormatValue // contains filtered or unexported fields }
func (*Config) SetDisableCaller ¶
SetDisableCaller dis- or enables the caller according to the provided flag if the flag was provided
func (*Config) SetDisableStacktrace ¶
SetDisableStacktrace dis- or enables the stackstrace according to the provided flag if the flag was provided
func (*Config) SetLogFormat ¶
SetLogFormat sets the logging format according to the provided flag if the flag was provided
func (*Config) SetLogLevel ¶
SetLogLevel sets the logging verbosity according to the provided flag if the flag was provided
func (*Config) SetTimestamp ¶
SetTimestamp dis- or enables the logging of timestamps according to the provided flag if the flag was provided
func (*Config) WithLogFormat ¶
func (*Config) WithLogLevel ¶
type KeyConflictPreventionLayer ¶
KeyConflictPreventionLayer is a helper struct. It implements logr.LogSink by containing a LogSink internally, to which all method calls are forwarded. The only purpose of this struct is to detect duplicate keys for logr.WithValues and replace them to avoid conflicts.
func (KeyConflictPreventionLayer) Enabled ¶
func (kcpl KeyConflictPreventionLayer) Enabled(level int) bool
func (KeyConflictPreventionLayer) Error ¶
func (kcpl KeyConflictPreventionLayer) Error(err error, msg string, keysAndValues ...interface{})
func (KeyConflictPreventionLayer) Info ¶
func (kcpl KeyConflictPreventionLayer) Info(level int, msg string, keysAndValues ...interface{})
func (KeyConflictPreventionLayer) Init ¶
func (kcpl KeyConflictPreventionLayer) Init(info logr.RuntimeInfo)
func (KeyConflictPreventionLayer) WithName ¶
func (kcpl KeyConflictPreventionLayer) WithName(name string) logr.LogSink
func (KeyConflictPreventionLayer) WithValues ¶
func (kcpl KeyConflictPreventionLayer) WithValues(keysAndValues ...interface{}) logr.LogSink
WithValues works as usual, but it will replace keys which already exist with a suffixed version indicating the conflict.
type Logger ¶
type Logger struct {
// contains filtered or unexported fields
}
var (
Log Logger
)
func FromContext ¶
FromContext wraps the result of logr.FromContext into a logging.Logger.
func FromContextOrDiscard ¶
FromContextOrDiscard works like FromContext, but it will return a discard logger if no logger is found in the context.
func FromContextOrNew ¶
func FromContextOrNew(ctx context.Context, keysAndValuesFallback []interface{}, keysAndValues ...interface{}) (Logger, context.Context)
FromContextOrNew tries to fetch a logger from the context. It is expected that a logger is contained in the context. If retrieving it fails, a new logger will be created and an error is logged. keysAndValuesFallback contains keys and values which will only be added if the logger could not be retrieved and a new one had to be created. The key-value-pairs from keysAndValues will always be added. A new context, containing the created logger, will be returned. The function panics if the logger cannot be fetched from the context and creating a new one fails.
func FromContextOrPanic ¶
FromContextOrPanic tries to fetch a logger from the context. If that fails, the function panics.
func FromContextWithFallback ¶
func FromContextWithFallback(ctx context.Context, fallback Logger, keysAndValues ...interface{}) (Logger, context.Context)
FromContextWithFallback tries to fetch a logger from the context. If that fails, the provided fallback logger is used instead. It returns the fetched logger, enriched with the given key-value-pairs, and a context containing this new logger.
func GetLogger ¶
GetLogger returns a singleton logger. Will initialize a new logger, if it doesn't exist yet.
func MustStartReconcileFromContext ¶
func MustStartReconcileFromContext(ctx context.Context, req reconcile.Request, keysAndValuesFallback []interface{}, keysAndValues ...interface{}) (Logger, context.Context)
MustStartReconcileFromContext is a helper function for easily getting a logger at the beginning of a reconciliation. It is basically a combination of FromContextOrNew, which tries to fetch the logger from the context, or creates a new one, if that fails, and StartReconcileAndAddToContext, which logs the beginning of the reconciliation and returns a new context containing the configured logger.
func NewCliLogger ¶
NewCliLogger creates a new logger for cli usage. CLI usage means that by default: - encoding is console - timestamps are disabled (can be still activated by the cli flag) - level are color encoded
func StartReconcileFromContext ¶
func StartReconcileFromContext(ctx context.Context, req reconcile.Request) (Logger, context.Context, error)
StartReconcileFromContext fetches the logger from the context and adds the reconciled resource. It also logs a 'start reconcile' message. The returned context contains the enriched logger.
func (Logger) Enabled ¶
Enabled tests whether logging at the provided level is enabled. This deviates from the logr Enabled() function, which doesn't take an argument.
func (Logger) Error ¶
Error logs an error, with the given message and key/value pairs as context. It functions similarly to calling Info with the "error" named value, but may have unique behavior, and should be preferred for logging errors (see the package documentations for more information).
The msg field should be used to add context to any underlying error, while the err field should be used to attach the actual error that triggered this log line, if present.
func (Logger) Info ¶
Info logs a non-error message with the given key/value pairs as context.
The msg argument should be used to add some constant description to the log line. The key/value pairs can then be used to add additional variable information. The key/value pairs should alternate string keys and arbitrary values.
func (Logger) IsInitialized ¶
IsInitialized returns true if the logger is ready to be used and false if it is an 'empty' logger (e.g. created by Logger{}).
func (Logger) Log ¶
Log logs at the given log level. It can be used to log at dynamically determined levels.
func (Logger) Reconciles ¶
Reconciles is meant to be used for the logger initialization for controllers. It is a wrapper for WithName(name).WithValues(lc.KeyReconciledResourceKind, reconciledResource).
func (Logger) StartReconcile ¶
StartReconcile works like StartReconcileFromContext, but it is called on an existing logger instead of fetching one from the context.
func (Logger) StartReconcileAndAddToContext ¶
func (l Logger) StartReconcileAndAddToContext(ctx context.Context, req reconcile.Request, keysAndValues ...interface{}) (Logger, context.Context)
StartReconcileAndAddToContext works like StartReconcile, but additionally returns a context with the new logger.
func (Logger) WithName ¶
WithName adds a new element to the logger's name. Successive calls with WithName continue to append suffixes to the logger's name. It's strongly recommended that name segments contain only letters, digits, and hyphens (see the package documentation for more information).
func (Logger) WithNameAndContext ¶
WithNameAndContext works like WithName, but also adds the logger directly to a context and returns the new context.
func (Logger) WithValues ¶
WithValues adds some key-value pairs of context to a logger. See Info for documentation on how key/value pairs work.