clog

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2021 License: ISC Imports: 3 Imported by: 0

README

clog

Go Reference

go get go.spiff.io/clog

clog is a simple package for attaching a Zap logger to a context, along with functions for logging from the context-attached logger or associating new fields to the logger.

Generally speaking this is a bad use of the context package, but utility won out over passing both a context and a logger around all the time. In particular, this is useful for passing a request-scoped logger through different http.Handler implementations that otherwise do not support Zap.

This is a fork of https://github.com/Kochava/clog.

Usage

A few examples of basic usage follow.

Attach a logger to a context
// var l *zap.Logger

// Attach the logger, l, to a context:
ctx := clog.WithLogger(context.Background(), l)

// Attach fields to the logger:
ctx = clog.With(ctx, zap.Int("field", 1234))

// Log at info level:
clog.Info(ctx, "Log message")

License

clog is made available under the ISC license. A copy of it can be found in the repository in the COPYING file.

Documentation

Overview

Package clog is a convenience package for passing Zap loggers through contexts.

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

Check is a convenience function for calling Logger(ctx).Check(lvl, msg).

func DPanic

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

DPanic is a convenience function for calling Logger(ctx).DPanic(msg, fields...).

func Debug

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

Debug is a convenience function for calling Logger(ctx).Debug(msg, fields...).

func Error

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

Error is a convenience function for calling Logger(ctx).Error(msg, fields...).

func Fatal

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

Fatal is a convenience function for calling Logger(ctx).Fatal(msg, fields...).

func Info

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

Info is a convenience function for calling Logger(ctx).Info(msg, fields...).

func Logger

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

Logger returns the zap.Logger for the given context.

func Panic

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

Panic is a convenience function for calling Logger(ctx).Panic(msg, fields...).

func Sugar

func Sugar(ctx context.Context) *zap.SugaredLogger

Sugar is a convenience function for calling Logger(ctx).Sugar().

func Warn

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

Warn is a convenience function for calling Logger(ctx).Warn(msg, fields...).

func With

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

With returns a context parented to ctx with a logger that has the given fields appended to it. The logger of ctx is the one returned by Logger.

func WithLogger

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

WithLogger returns a context parented to ctx with the given logger attached as a value.

func WithOptions

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

WithOptions is a convenience function for calling WithLogger(ctx, Logger(ctx).WithOptions(opts...)).

Types

This section is empty.

Jump to

Keyboard shortcuts

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