lg

package
v0.43.1 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2023 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package lg contains utility functions for working with slog. It implements the slog.NewContext and slog.FromContext funcs that have recently been zapped from the slog proposal. I think you had it right the first time, Go team. Hopefully this package is short-lived and those funcs are put back.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Discard

func Discard() *slog.Logger

Discard returns a new *slog.Logger that discards output.

func Error

func Error(log *slog.Logger, msg string, err error, args ...any)

Error logs an error if err is non-nil.

func FromContext

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

FromContext returns the Logger stored in ctx by NewContext, or the Discard logger if there is none.

func InContext added in v0.38.0

func InContext(ctx context.Context) bool

InContext returns true if there's a logger on the context.

func NewContext

func NewContext(ctx context.Context, l *slog.Logger) context.Context

NewContext returns a context that contains the given Logger. Use FromContext to retrieve the Logger.

func Unexpected

func Unexpected(log *slog.Logger, err error)

Unexpected is a convenience function for logging unexpected errors for which there may not be any useful context message.

func WarnIfCloseError

func WarnIfCloseError(log *slog.Logger, msg string, c io.Closer)

WarnIfCloseError executes c.Close if is non-nil, and logs a warning if c.Close returns an error.

func WarnIfError

func WarnIfError(log *slog.Logger, msg string, err error)

WarnIfError logs a warning if err is non-nil.

func WarnIfFuncError

func WarnIfFuncError(log *slog.Logger, msg string, fn func() error)

WarnIfFuncError executes fn (if non-nil), and logs a warning if fn returns an error.

Types

This section is empty.

Directories

Path Synopsis
Package lga ("log attribute") holds constants for log attribute names.
Package lga ("log attribute") holds constants for log attribute names.
Package lgm ("log message") contains constants for log messages.
Package lgm ("log message") contains constants for log messages.
Package slogbuf implements a Buffer that stores log records that can later be replayed on a slog.Handler.
Package slogbuf implements a Buffer that stores log records that can later be replayed on a slog.Handler.
Package userlogdir has a single function, UserLogDir, that returns an OS-specific path for storing user logs.
Package userlogdir has a single function, UserLogDir, that returns an OS-specific path for storing user logs.

Jump to

Keyboard shortcuts

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