logging

package module
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2025 License: MIT Imports: 3 Imported by: 1

README

go-logging

Some useful patterns for service logging in Go that I've been copy-pasting between projects for a while now...

RTFM

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Error added in v0.2.0

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

Error is a helper to log a single error-level message to a Context logger

func FromContext

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

FromContext attempts to retrieve a Logger from a Context's values

func Info

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

Info is a helper to log a single info-level message to a Context logger

func Named

func Named(ctx context.Context, name string, fields ...zap.Field) (context.Context, *zap.Logger)

Named appends a name to a Logger and re-injects it into a child Context

func New

func New(ctx context.Context, core zapcore.Core, opts ...zap.Option) context.Context

New creates a new Logger from a Core and options, and injects it into a Context

func With

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

With adds fields to a Logger and re-injects it into a child Context

func WithLogger

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

WithLogger adds an existing Logger to a Context's values

Types

type Level

type Level struct {
	zap.AtomicLevel
}

Level extends zapcore.Level with pflag.Flag methods

func NewLevel

func NewLevel(lvl zapcore.Level) *Level

NewLevel instantiates a new Level register for an initial zapcore.Level

func (*Level) Set

func (lvl *Level) Set(val string) error

Set implements the pflag.Flag setter

func (*Level) Type

func (*Level) Type() string

Type implements the pflag.Flag interface for usage printing

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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