Documentation
¶
Overview ¶
Package zap contains helpers for setting up a new logr.Logger instance using the Zap logging framework.
Index ¶
- func Logger(development bool) logr.Logger
- func LoggerTo(destWriter io.Writer, development bool) logr.Logger
- func New(opts ...Opts) logr.Logger
- func NewRaw(opts ...Opts) *zap.Logger
- func RawLoggerTo(destWriter io.Writer, development bool, opts ...zap.Option) *zap.Logger
- type KubeAwareEncoder
- type Options
- type Opts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Logger ¶
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(func(o *Options){
o.Development: development,
})
func LoggerTo ¶
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(func(o *Options){
o.Development: development,
o.DestWriter: 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 ¶
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(func(o *Options){
o.Development: development,
})
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 {
// 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).
Development bool
// The encoder to use, defaults to console when Development is true
// and JSON otherwise
Encoder zapcore.Encoder
// The destination to write to, defaults to os.Stderr
DestWritter io.Writer
// The level to use, defaults to Debug when Development is true and
// Info otherwise
Level *zap.AtomicLevel
// 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 *zap.AtomicLevel
// Raw zap.Options to configure on the underlying zap logger
ZapOpts []zap.Option
}
Options contains all possible settings