Documentation ¶
Overview ¶
Package zapctx provides support for associating zap loggers (see github.com/uber-go/zap) with contexts.
Index ¶
- Variables
- func Debug(ctx context.Context, msg string, fields ...zapcore.Field)
- func Error(ctx context.Context, msg string, fields ...zapcore.Field)
- func Info(ctx context.Context, msg string, fields ...zapcore.Field)
- func Logger(ctx context.Context) *zap.Logger
- func Warn(ctx context.Context, msg string, fields ...zapcore.Field)
- func WithFields(ctx context.Context, fields ...zapcore.Field) context.Context
- func WithLevel(ctx context.Context, level zapcore.Level) context.Context
- func WithLogger(ctx context.Context, logger *zap.Logger) context.Context
Constants ¶
This section is empty.
Variables ¶
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.
var LogLevel = zap.NewAtomicLevel()
LogLevel holds an AtomicLevel that can be used to change the logging level of Default.
Functions ¶
func Logger ¶
Logger returns the logger associated with the given context. If there is no logger, it will return Default.
func WithFields ¶
WithFields returns a new context derived from ctx that has a logger that always logs the given fields.
Types ¶
This section is empty.