Documentation ¶
Index ¶
- Constants
- Variables
- func AlwaysFromContext(ctx context.Context) logr.Logger
- func ContextWithName(ctx context.Context, name string) context.Context
- func ContextWithNameAndValues(ctx context.Context, name string, keysAndValues ...interface{}) context.Context
- func ContextWithValues(ctx context.Context, keysAndValues ...interface{}) context.Context
- func Debug(ctx context.Context, message string, keysAndValues ...interface{})
- func Discard() logr.Logger
- func Error(ctx context.Context, err error, message string, keysAndValues ...interface{})
- func Info(ctx context.Context, message string, keysAndValues ...interface{})
- func NewContext(ctx context.Context, log logr.Logger) context.Context
- func NewLogger(configurator Configurator, rootName string, verbosity int) (logr.Logger, error)
- func NewLoggerFromEnv(rootname string) (logr.Logger, error)
- func NewLoggerWithBuildInfo(configurator Configurator, buildInfo BuildInfo, rootName string, verbosity int) (logr.Logger, error)
- func V(ctx context.Context, level int) logr.Logger
- func Warn(ctx context.Context, message string, keysAndValues ...interface{})
- func WarnWrap(ctx context.Context, err error, message string, keysAndValues ...interface{}) error
- func Warning(ctx context.Context, message string, keysAndValues ...interface{})
- func WithName(ctx context.Context, name string) (context.Context, logr.Logger)
- func WithNameAndValues(ctx context.Context, name string, keysAndValues ...interface{}) (context.Context, logr.Logger)
- func WithValues(ctx context.Context, keysAndValues ...interface{}) (context.Context, logr.Logger)
- func Wrap(ctx context.Context, err error, message string, keysAndValues ...interface{}) error
- type BuildInfo
- type Configurator
- type ZapConfigurator
Constants ¶
const ( LogProduction = "LOG_PRODUCTION" LogImplementation = "LOG_IMPLEMENTATION" LogVerbosity = "LOG_VERBOSITY" )
const ( // MaxLevel is the maximum logging level supported. All verbosity values higher will be // clamped to this value. MaxLevel = 127 // MinLevel is the minimum logging level supported. All verbosity values lower will be // clamped to this value. MinLevel = 0 )
Variables ¶
var DefaultFallbackOutput io.Writer = os.Stdout
DefaultFallbackOutput is the default io stream jfor fallback logging.
var ErrUnknownImplementation = errors.New("unknown implementation")
Functions ¶
func AlwaysFromContext ¶
AlwaysFromContext retrieves the logger from the context, if it is not found a new production logger at `MaxLevel` will be returned. If that fails a `fmt.Println` based logger is returned.
func ContextWithName ¶
ContextWithName returns a context with the name set in its logger.
func ContextWithNameAndValues ¶ added in v1.3.0
func ContextWithNameAndValues( ctx context.Context, name string, keysAndValues ...interface{}, ) context.Context
ContextWithNameAndValues returns a context with the name and values set in its logger.
func ContextWithValues ¶
ContextWithValues returns a context with the values set in its logger.
func Debug ¶ added in v1.3.0
Debug get a logger from the given context at one level higher than the current level and log the message. Prepends `severity=debug` to the passed key/value.
func Discard ¶ added in v1.4.0
Discard returns a Logger that discards all messages logged to it. It can be used whenever the caller is not interested in the logs. Logger instances produced by this function always compare as equal. This is just a proxy to `logr.Discard`.
func Error ¶ added in v1.2.0
Error gets a logger from the given context and logs the error and message and optional values with `severity=error` prepended into the passed key/value.
func Info ¶ added in v1.1.0
Info gets a logger from the given context and logs message and optional values with `severity=info` prepended into the passed key/value.
func NewContext ¶
NewContext returns a context with the specified logger set in it.
func NewLogger ¶
NewLogger sets the log verbosity, configures a new logger from `configurator`, and sets the initial name of the logger.
func NewLoggerFromEnv ¶
NewLoggerFromEnv uses the environment variables `LOG_PRODUCTION`, `LOG_IMPLEMENTATION`, and `LOG_VERBOSITY` to configure the logger. If they do not exist, it will default to configuring a production logger, with a `zap` `Configurator` at `0` verbosity (normal / info level).
func NewLoggerWithBuildInfo ¶
func NewLoggerWithBuildInfo( configurator Configurator, buildInfo BuildInfo, rootName string, verbosity int, ) (logr.Logger, error)
NewLogger sets the log verbosity, configures a new logger from `configurator`, and sets the initial name of the logger. If `buildInfo` is not `nil`, non-empty values from the interface will be set as values on the resulting `logr.Logger`.
func Warn ¶ added in v1.3.0
Warn gets a logger from the given context and logs the message with `severity=warning` prepended into the passed key/value.
func WarnWrap ¶ added in v1.5.0
func WarnWrap( ctx context.Context, err error, message string, keysAndValues ...interface{}, ) error
WarnWrap logs the error as a warning and returns it wrapped by message. Useful for handling expected errors that should not be logged at error level.
func WithName ¶ added in v1.2.0
WithName returns a context and logger with the given `name` set in the context.
func WithNameAndValues ¶ added in v1.2.0
func WithNameAndValues( ctx context.Context, name string, keysAndValues ...interface{}, ) (context.Context, logr.Logger)
WithNameAndValues returns a context and logger with the given `name` and `values` set in the context.
func WithValues ¶ added in v1.2.0
WithValues returns a context and logger with the given `values` set in the context.
Types ¶
type BuildInfo ¶
BuildInfo allows the application to add build info to the logger by default. Any non empty value returned will be set in the logger when calling `NewLoggerWithBuildInfo`.
type Configurator ¶
type Configurator interface { // Build and return a `logr.Logger` instance. Build() (logr.Logger, error) // Verbosity sets the desired verbosity level. NOTE this will be called prior to `Build`. Verbosity(verbosity int) error }
Configurator allows a pluggable logging implementation.
var DefaultConfigurator Configurator = NewZapProductionConfigurator()
DefaultConfigurator is the default configurator for fallback logging.
type ZapConfigurator ¶
func NewZapDevelopmentConfigurator ¶
func NewZapDevelopmentConfigurator() *ZapConfigurator
func NewZapProductionConfigurator ¶
func NewZapProductionConfigurator() *ZapConfigurator
func (*ZapConfigurator) Build ¶
func (config *ZapConfigurator) Build() (logr.Logger, error)
Build a new `zap` `logr.Logger`.
func (*ZapConfigurator) Verbosity ¶
func (config *ZapConfigurator) Verbosity(verbosity int) error
Verbosity sets the desirect log verbosity in the `zap` config.