ctxlog

package module
v0.0.0-...-f475ac5 Latest Latest
Warning

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

Go to latest
Published: May 26, 2021 License: MIT Imports: 3 Imported by: 8

README

ctxlog

A context-based wrapper for the zap logger.

import (
    "context"

    "github.com/zikaeroh/ctxlog"
    "go.uber.org/zap"
)

func doSomething(ctx context.Context) {
    ctxlog.Debug(ctx, "something happened", zap.Int("cool", 1234))
    // ...
}

Documentation

Overview

Package ctxlog provides context-scoped logging.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Debug

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

Debug writes a log item with the debug level.

func Error

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

Error writes a log item with the error level.

func Fatal

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

Fatal writes a log item with the fatal level.

func FromContext

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

FromContext gets a zap logger from a context. If none is set, then a nop logger is returned. The Debug, Error, With, WithOptions, etc, functions should be preferred over using this function to access a logger.

func Info

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

Info writes a log item with the info level.

func New

func New(debug bool) *zap.Logger

New creates a new zap Logger.

func NewUnsampled

func NewUnsampled(debug bool) *zap.Logger

NewUnsampled creates a new zap logger with sampling disabled.

func NoTrace

func NoTrace() zap.Option

NoTrace disables stack traces in log events.

func PlainError

func PlainError(err error) zap.Field

PlainError is like zap.Error, but won't also include extra debugging info (which is duplicated in some logging levels).

func Warn

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

Warn writes a log item with the warning level.

func With

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

With returns a new context with the provided fields.

func WithLogger

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

WithLogger adds a zap logger to a context.

func WithOptions

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

WithOptions returns a context containing a logger with the specified options.

Types

This section is empty.

Jump to

Keyboard shortcuts

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