Documentation
¶
Overview ¶
Package textlogger contains an implementation of the logr interface which is producing the exact same output as klog.
Experimental ¶
Notice: This package is EXPERIMENTAL and may be changed or removed in a later release.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ( // TimeNow is used to retrieve the current time. May be changed for testing. // // Experimental // // Notice: This variable is EXPERIMENTAL and may be changed or removed in a // later release. TimeNow = time.Now )
Functions ¶
Types ¶
type Config ¶
type Config struct {
// contains filtered or unexported fields
}
Config influences logging in a text logger. To make this configurable via command line flags, instantiate this once per program and use AddFlags to bind command line flags to the instance before passing it to NewTestContext.
Must be constructed with NewConfig.
Experimental ¶
Notice: This type is EXPERIMENTAL and may be changed or removed in a later release.
func NewConfig ¶
func NewConfig(opts ...ConfigOption) *Config
NewConfig returns a configuration with recommended defaults and optional modifications. Command line flags are not bound to any FlagSet yet.
Experimental ¶
Notice: This function is EXPERIMENTAL and may be changed or removed in a later release.
func (*Config) AddFlags ¶
AddFlags registers the command line flags that control the configuration.
Experimental ¶
Notice: This function is EXPERIMENTAL and may be changed or removed in a later release.
func (*Config) VModule ¶ added in v2.90.1
VModule returns a value instance that can be used to query (via String) or modify (via Set) the vmodule settings. This is thread-safe and can be done at runtime.
func (*Config) Verbosity ¶ added in v2.90.1
Verbosity returns a value instance that can be used to query (via String) or modify (via Set) the verbosity threshold. This is thread-safe and can be done at runtime.
Example ¶
package main import ( "bytes" "fmt" "regexp" "k8s.io/klog/v2/textlogger" ) var headerRe = regexp.MustCompile(`([IE])[[:digit:]]{4} [[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}\.[[:digit:]]{6}[[:space:]]+[[:digit:]]+ example_test.go:[[:digit:]]+\] `) func main() { var buffer bytes.Buffer config := textlogger.NewConfig(textlogger.Verbosity(1), textlogger.Output(&buffer)) logger := textlogger.NewLogger(config) logger.Info("initial verbosity", "v", config.Verbosity().String()) logger.V(2).Info("now you don't see me") if err := config.Verbosity().Set("2"); err != nil { logger.Error(err, "setting verbosity to 2") } logger.V(2).Info("now you see me") if err := config.Verbosity().Set("1"); err != nil { logger.Error(err, "setting verbosity to 1") } logger.V(2).Info("now I'm gone again") fmt.Print(headerRe.ReplaceAllString(buffer.String(), "${1}...] ")) }
Output: I...] "initial verbosity" v="1" I...] "now you see me"
type ConfigOption ¶
type ConfigOption func(co *configOptions)
ConfigOption implements functional parameters for NewConfig.
Experimental ¶
Notice: This type is EXPERIMENTAL and may be changed or removed in a later release.
func Output ¶
func Output(output io.Writer) ConfigOption
Output overrides stderr as the output stream.
Experimental ¶
Notice: This function is EXPERIMENTAL and may be changed or removed in a later release.
func VModuleFlagName ¶
func VModuleFlagName(name string) ConfigOption
VModulFlagName overrides the default -vmodule for the per-module verbosity levels.
Experimental ¶
Notice: This function is EXPERIMENTAL and may be changed or removed in a later release.
func Verbosity ¶
func Verbosity(level int) ConfigOption
Verbosity overrides the default verbosity level of 0. See https://github.com/kubernetes/community/blob/9406b4352fe2d5810cb21cc3cb059ce5886de157/contributors/devel/sig-instrumentation/logging.md#logging-conventions for log level conventions in Kubernetes.
Experimental ¶
Notice: This function is EXPERIMENTAL and may be changed or removed in a later release.
func VerbosityFlagName ¶
func VerbosityFlagName(name string) ConfigOption
VerbosityFlagName overrides the default -v for the verbosity level.
type KlogBufferWriter ¶ added in v2.90.1
type KlogBufferWriter interface { // WriteKlogBuffer takes a pre-formatted buffer prepared by klog and // writes it unchanged to the output stream. Can be used with // klog.WriteKlogBuffer when setting a logger through // klog.SetLoggerWithOptions. WriteKlogBuffer([]byte) }
KlogBufferWriter is implemented by the textlogger LogSink.