ctxzap

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 4, 2022 License: MIT Imports: 3 Imported by: 0

README

ctxzap

Attach your zap.Logger to context.Context. Package documentation

Usage

// If ctx contains a zap.Logger, this is equivalent to a call to Info on the zap.Logger,
// if the ctx does not contain a zap.Logger, this is equivalent to a call to Info on a Nop zap.Logger.
ctxzap.Info(ctx, "message", zap.String("key", "val"))

// It is possible to obtain a derived context with the specified zapcore.Fields.
// This is equivalent to calling With() on the zap.Logger in the context, and creating a new context
// with the zap.Logger returned by With()
ctx = ctxzap.With(ctx, zap.String("foo", "bar"))

// It is possible to extract the zap.Logger in the context with Logger, and attach a custom logger
// to a context with WithLogger.
logger := ctxzap.Logger(ctx)

// ...modify logger as needed...

ctx = ctxzap.WithLogger(ctx, logger)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Check

func Check(ctx context.Context, lvl zapcore.Level, msg string) *zapcore.CheckedEntry

func DPanic

func DPanic(ctx context.Context, msg string, fields ...zapcore.Field)

func Debug

func Debug(ctx context.Context, msg string, fields ...zapcore.Field)

func Error

func Error(ctx context.Context, msg string, fields ...zapcore.Field)

func Fatal

func Fatal(ctx context.Context, msg string, fields ...zapcore.Field)

func Info

func Info(ctx context.Context, msg string, fields ...zapcore.Field)

func Logger

func Logger(ctx context.Context) *zap.Logger

func Named

func Named(ctx context.Context, name string) context.Context

func Panic

func Panic(ctx context.Context, msg string, fields ...zapcore.Field)

func Sync

func Sync(ctx context.Context) error

func Warn

func Warn(ctx context.Context, msg string, fields ...zapcore.Field)

func With

func With(ctx context.Context, fields ...zapcore.Field) context.Context

func WithLogger

func WithLogger(ctx context.Context, l *zap.Logger) context.Context

func WithOptions

func WithOptions(ctx context.Context, options ...zap.Option) context.Context

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL