zapctx

package
v0.0.0-...-ef53049 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2019 License: LGPL-3.0 Imports: 4 Imported by: 30

Documentation

Overview

Package zapctx provides support for associating zap loggers (see github.com/uber-go/zap) with contexts.

Index

Constants

This section is empty.

Variables

View Source
var Default = zap.New(
	zapcore.NewCore(
		zapcore.NewJSONEncoder(zapcore.EncoderConfig{
			MessageKey:  "msg",
			LevelKey:    "level",
			TimeKey:     "ts",
			EncodeLevel: zapcore.LowercaseLevelEncoder,
			EncodeTime:  zapcore.ISO8601TimeEncoder,
		}),
		os.Stdout,
		&LogLevel,
	),
)

Default holds the logger returned by Logger when there is no logger in the context. If replacing Default with a new Logger then consider using &LogLevel as the LevelEnabler so that SetLevel can still be used to dynamically change the logging level.

View Source
var LogLevel = zap.NewAtomicLevel()

LogLevel holds an AtomicLevel that can be used to change the logging level of Default.

Functions

func Debug

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

Debug calls Logger(ctx).Debug(msg, fields...).

func Error

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

Error calls Logger(ctx).Error(msg, fields...).

func Info

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

Info calls Logger(ctx).Info(msg, fields...).

func Logger

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

Logger returns the logger associated with the given context. If there is no logger, it will return Default.

func Warn

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

Warn calls Logger(ctx).Warn(msg, fields...).

func WithFields

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

WithFields returns a new context derived from ctx that has a logger that always logs the given fields.

func WithLevel

func WithLevel(ctx context.Context, level zapcore.Level) context.Context

WithLevel returns a new context derived from ctx that has a logger that only logs messages at or above the given level.

func WithLogger

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

WithLogger returns a new context derived from ctx that is associated with the given logger.

Types

This section is empty.

Jump to

Keyboard shortcuts

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