Documentation ¶
Overview ¶
Package zap contains helpers for setting up a new logr.Logger instance using the Zap logging framework.
Package zap contains helpers for setting up a new logr.Logger instance using the Zap logging framework.
Index ¶
- func Encoder(encoder zapcore.Encoder) func(o *Options)
- func Level(level zapcore.LevelEnabler) func(o *Options)
- func Logger(development bool) logr.Loggerdeprecated
- func LoggerTo(destWriter io.Writer, development bool) logr.Loggerdeprecated
- func New(opts ...Opts) logr.Logger
- func NewRaw(opts ...Opts) *zap.Logger
- func RawLoggerTo(destWriter io.Writer, development bool, opts ...zap.Option) *zap.Loggerdeprecated
- func RawZapOpts(zapOpts ...zap.Option) func(o *Options)
- func StacktraceLevel(stacktraceLevel zapcore.LevelEnabler) func(o *Options)
- type KubeAwareEncoder
- type Options
- type Opts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Encoder ¶ added in v0.4.0
Encoder configures how the logger will encode the output e.g JSON or console. See Options.Encoder
func Level ¶ added in v0.4.0
func Level(level zapcore.LevelEnabler) func(o *Options)
Level sets the the minimum enabled logging level e.g Debug, Info See Options.Level
func Logger
deprecated
Logger is a Logger implementation. If development is true, a Zap development config will be used (stacktraces on warnings, no sampling), otherwise a Zap production config will be used (stacktraces on errors, sampling).
Deprecated: use New() and the functional opts pattern instead:
New(UseDevMode(development))
func LoggerTo
deprecated
LoggerTo returns a new Logger implementation using Zap which logs to the given destination, instead of stderr. It otherwise behaves like ZapLogger.
Deprecated: use New() and the functional opts pattern instead:
New(UseDevMode(development), WriteTo(writer))
func New ¶ added in v0.2.1
New returns a brand new Logger configured with Opts. It uses KubeAwareEncoder which adds Type information and Namespace/Name to the log.
func NewRaw ¶ added in v0.2.1
NewRaw returns a new zap.Logger configured with the passed Opts or their defaults. It uses KubeAwareEncoder which adds Type information and Namespace/Name to the log.
func RawLoggerTo
deprecated
RawLoggerTo returns a new zap.Logger configured with KubeAwareEncoder which logs to a given destination
Deprecated: use NewRaw() and the functional opts pattern instead:
NewRaw(UseDevMode(development), WriteTo(destWriter), RawZapOpts(opts...))
func RawZapOpts ¶ added in v0.4.0
RawZapOpts allows appending arbitrary zap.Options to configure the underlying zap logger. See Options.ZapOpts
func StacktraceLevel ¶ added in v0.4.0
func StacktraceLevel(stacktraceLevel zapcore.LevelEnabler) func(o *Options)
StacktraceLevel configures the logger to record a stack trace for all messages at or above a given level. See Options.StacktraceLevel
Types ¶
type KubeAwareEncoder ¶
type KubeAwareEncoder struct { // Encoder is the zapcore.Encoder that this encoder delegates to zapcore.Encoder // Verbose controls whether or not the full object is printed. // If false, only name, namespace, api version, and kind are printed. // Otherwise, the full object is logged. Verbose bool }
KubeAwareEncoder is a Kubernetes-aware Zap Encoder. Instead of trying to force Kubernetes objects to implement ObjectMarshaller, we just implement a wrapper around a normal ObjectMarshaller that checks for Kubernetes objects.
func (*KubeAwareEncoder) Clone ¶
func (k *KubeAwareEncoder) Clone() zapcore.Encoder
Clone implements zapcore.Encoder
func (*KubeAwareEncoder) EncodeEntry ¶
func (k *KubeAwareEncoder) EncodeEntry(entry zapcore.Entry, fields []zapcore.Field) (*buffer.Buffer, error)
EncodeEntry implements zapcore.Encoder
type Options ¶ added in v0.2.1
type Options struct { // Development configures the logger to use a Zap development config // (stacktraces on warnings, no sampling), otherwise a Zap production // config will be used (stacktraces on errors, sampling). Development bool // Encoder configures how Zap will encode the output. Defaults to // console when Development is true and JSON otherwise Encoder zapcore.Encoder // DestWritter controls the destination of the log output. Defaults to // os.Stderr. DestWritter io.Writer // Level configures the verbosity of the logging. Defaults to Debug when // Development is true and Info otherwise Level zapcore.LevelEnabler // StacktraceLevel is the level at and above which stacktraces will // be recorded for all messages. Defaults to Warn when Development // is true and Error otherwise StacktraceLevel zapcore.LevelEnabler // ZapOpts allows passing arbitrary zap.Options to configure on the // underlying Zap logger. ZapOpts []zap.Option }
Options contains all possible settings
func (*Options) BindFlags ¶ added in v0.5.2
BindFlags will parse the given flagset for zap option flags and set the log options accordingly
zap-devel: Development Mode defaults(encoder=consoleEncoder,logLevel=Debug,stackTraceLevel=Warn) Production Mode defaults(encoder=jsonEncoder,logLevel=Info,stackTraceLevel=Error) zap-encoder: Zap log encoding ('json' or 'console') zap-log-level: Zap Level to configure the verbosity of logging. Can be one of 'debug', 'info', 'error', or any integer value > 0 which corresponds to custom debug levels of increasing verbosity") zap-stacktrace-level: Zap Level at and above which stacktraces are captured (one of 'warn' or 'error')
type Opts ¶ added in v0.2.1
type Opts func(*Options)
Opts allows to manipulate Options
func UseDevMode ¶ added in v0.4.0
UseDevMode sets the logger to use (or not use) development mode (more human-readable output, extra stack traces and logging information, etc). See Options.Development
func UseFlagOptions ¶ added in v0.5.2
UseFlagOptions configures the logger to use the Options set by parsing zap option flags from the CLI.
opts := zap.Options{} opts.BindFlags(flag.CommandLine) log := zap.New(zap.UseFlagOptions(&opts))