component-basek8s.io/component-base/logs Index | Files | Directories

package logs

import "k8s.io/component-base/logs"

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

const (
	DefaultLogFormat = "text"
	JSONLogFormat    = "json"
)

Supported klog formats

Functions

func AddFlags

func AddFlags(fs *pflag.FlagSet)

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

func AddGoFlags(fs *flag.FlagSet)

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 BindLoggingFlags

func BindLoggingFlags(c *config.LoggingConfiguration, fs *pflag.FlagSet)

BindLoggingFlags binds the Options struct fields to a flagset

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

func GlogSetter(val string) (string, error)

GlogSetter is a setter to set glog level.

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.

func NewLogger

func NewLogger(prefix string) *log.Logger

NewLogger creates a new log.Logger which sends logs to klog.Info.

func UnsupportedLoggingFlags

func UnsupportedLoggingFlags(normalizeFunc func(f *pflag.FlagSet, name string) pflag.NormalizedName) []*pflag.Flag

UnsupportedLoggingFlags lists unsupported logging flags. The normalize function is optional.

func ValidateLoggingConfiguration

func ValidateLoggingConfiguration(c *config.LoggingConfiguration, fldPath *field.Path) field.ErrorList

Types

type KlogWriter

type KlogWriter struct{}

KlogWriter serves as a bridge between the standard log package and the glog package.

func (KlogWriter) Write

func (writer KlogWriter) Write(data []byte) (n int, err error)

Write implements the io.Writer interface.

type Options

type Options struct {
	Config config.LoggingConfiguration
}

Options has klog format parameters

func NewOptions

func NewOptions() *Options

NewOptions return new klog options

func (*Options) AddFlags

func (o *Options) AddFlags(fs *pflag.FlagSet)

AddFlags add logging-format flag

func (*Options) Apply

func (o *Options) Apply()

Apply set klog logger from LogFormat type

func (*Options) Validate

func (o *Options) Validate() []error

Validate verifies if any unsupported flag is set for non-default logging format

Source Files

config.go logs.go options.go validate.go

Directories

PathSynopsis
logs/datapolPackage datapol contains functions to determine if objects contain sensitive data to e.g.
logs/example
logs/example/cmd
logs/json
logs/json/register
logs/logreduction
logs/registry
logs/sanitization
logs/testinitPackage testinit adds logging flags to a Ginkgo or Go test program during initialization, something that the logs package itself no longer does.
Version
v0.23.0-alpha.4
Published
Nov 3, 2021
Platform
js/wasm
Imports
15 packages
Last checked
7 minutes ago

Tools for package owners.