var ( // TimeNow is used to retrieve the current time. May be changed for testing. TimeNow = time.Now )
func NewLogger(c *Config) logr.Logger
NewLogger constructs a new logger.
Verbosity can be modified at any time through the Config.V and Config.VModule API.
▹ Example
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.
type Config struct {
// contains filtered or unexported fields
}
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.
func (c *Config) AddFlags(fs *flag.FlagSet)
AddFlags registers the command line flags that control the configuration.
The default flag names are the same as in klog, so unless those defaults are changed, either klog.InitFlags or Config.AddFlags can be used for the same flag set, but not both.
func (c *Config) VModule() flag.Value
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 (c *Config) Verbosity() flag.Value
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
ConfigOption implements functional parameters for NewConfig.
type ConfigOption func(co *configOptions)
func Backtrace(unwind func(skip int) (filename string, line int)) ConfigOption
Backtrace overrides the default mechanism for determining the call site. The callback is invoked with the number of function calls between itself and the call site. It must return the file name and line number. An empty file name indicates that the information is unknown.
Notice: This function is EXPERIMENTAL and may be changed or removed in a later release.
▹ Example
func FixedTime(ts time.Time) ConfigOption
FixedTime overrides the actual time with a fixed time. Useful only for testing.
Notice: This function is EXPERIMENTAL and may be changed or removed in a later release.
func Output(output io.Writer) ConfigOption
Output overrides stderr as the output stream.
func VModuleFlagName(name string) ConfigOption
VModulFlagName overrides the default -vmodule for the per-module verbosity levels.
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.
func VerbosityFlagName(name string) ConfigOption
VerbosityFlagName overrides the default -v for the verbosity level.
KlogBufferWriter is implemented by the textlogger LogSink.
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) }