Documentation ¶
Overview ¶
Package logs contains support for logging options, flags and setup. Commands must explicitly enable command line flags. They no longer get added automatically when importing this package.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NewOptions = logsapi.NewLoggingConfiguration
NewOptions is an alias for NewLoggingConfiguration.
Functions ¶
func AddFlags ¶
AddFlags registers this package's flags on arbitrary FlagSets. This includes the klog flags, with the original underscore as separator between. If commands want hyphens as separators, they can set k8s.io/component-base/cli/flag/WordSepNormalizeFunc as normalization function on the flag set before calling AddFlags.
May be called more than once.
func AddGoFlags ¶ added in v0.23.0
AddGoFlags is a variant of AddFlags for traditional Go flag.FlagSet. Commands should use pflag whenever possible for the sake of consistency. Cases where this function is needed include tests (they have to set up flags in flag.CommandLine) and commands that for historic reasons use Go flag.Parse and cannot change to pflag because it would break their command line interface.
func FlushLogs ¶
func FlushLogs()
FlushLogs flushes logs immediately. This should be called at the end of the main function via defer to ensure that all pending log messages are printed before exiting the program.
func GlogSetter ¶
GlogSetter modifies the verbosity threshold for the entire program. Some components have HTTP-based APIs for invoking this at runtime.
func InitLogs ¶
func InitLogs()
InitLogs initializes logs the way we want for Kubernetes. It should be called after parsing flags. If called before that, it will use the default log settings.
InitLogs disables support for contextual logging in klog while that Kubernetes feature is not considered stable yet. Commands which want to support contextual logging can:
- call klog.EnableContextualLogging after calling InitLogs, with a fixed `true` or depending on some command line flag or a feature gate check
- set up a FeatureGate instance, the advanced logging configuration with Options and call Options.ValidateAndApply with the FeatureGate; k8s.io/component-base/logs/example/cmd demonstrates how to do that
Types ¶
type KlogWriter ¶
type KlogWriter struct{}
KlogWriter serves as a bridge between the standard log package and the glog package.
type Option ¶ added in v0.23.0
type Option func(*addFlagsOptions)
func SkipLoggingConfigurationFlags ¶ added in v0.23.0
func SkipLoggingConfigurationFlags() Option
SkipLoggingConfigurationFlags must be used as option for AddFlags when the program also uses a LoggingConfiguration struct for configuring logging. Then only flags not covered by that get added.
type Options ¶ added in v0.19.0
type Options = logsapi.LoggingConfiguration
Options is an alias for LoggingConfiguration to comply with component-base conventions.
Directories ¶
Path | Synopsis |
---|---|
api
|
|
v1
The LoggingAlphaOptions and LoggingBetaOptions feature gates control whether these unstable features can get enabled.
|
The LoggingAlphaOptions and LoggingBetaOptions feature gates control whether these unstable features can get enabled. |
Package datapol contains functions to determine if objects contain sensitive data to e.g.
|
Package datapol contains functions to determine if objects contain sensitive data to e.g. |
Package example shows how a library uses contextual logging.
|
Package example shows how a library uses contextual logging. |
slog2k8s
slog2k8s demonstrates how an application using log/slog for logging can include Kubernetes packages.
|
slog2k8s demonstrates how an application using log/slog for logging can include Kubernetes packages. |
internal
|
|
setverbositylevel
Package setverbositylevel stores callbacks that will be invoked by logs.GlogLevel.
|
Package setverbositylevel stores callbacks that will be invoked by logs.GlogLevel. |
Package testinit adds logging flags to a Ginkgo or Go test program during initialization, something that the logs package itself no longer does.
|
Package testinit adds logging flags to a Ginkgo or Go test program during initialization, something that the logs package itself no longer does. |