Documentation ¶
Index ¶
- Constants
- Variables
- func AlwaysFromContext(ctx context.Context) logr.Logger
- func ContextWithName(ctx context.Context, name string) context.Context
- func ContextWithValues(ctx context.Context, keysAndValues ...interface{}) context.Context
- 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 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. nolint: gochecknoglobals // Allow for testing
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. nolint:contextcheck // ALWAYS!
func ContextWithName ¶
ContextWithName returns a context with the name set in its logger.
func ContextWithValues ¶
ContextWithValues returns a context with the values set in its logger.
func Info ¶ added in v1.1.0
Gets a logger from the given context and logs message and optional values.
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`.
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. nolint: gochecknoglobals // Allow for testing
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.