logging

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MPL-2.0 Imports: 4 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromContext

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

FromContext returns the logger in ctx, or a logger that discards every record when ctx has none.

func NewContext

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

NewContext returns a copy of ctx that carries logger.

func NewHandler

func NewHandler(w io.Writer, format Format, level slog.Level) slog.Handler

NewHandler returns the slog handler for format that writes records at level or above to w. FormatText uses slog.TextHandler, which writes logfmt key=value lines. FormatJSON uses slog.JSONHandler. Both resolve slog.LogValuer attributes.

Types

type Format

type Format string

Format names an output format that the --format flag selects.

const (
	// FormatText selects logfmt text output.
	FormatText Format = "text"
	// FormatJSON selects one JSON object per line.
	FormatJSON Format = "json"
)

func ParseFormat

func ParseFormat(s string) (Format, error)

ParseFormat returns the Format named by s, or an error that lists the valid formats.

Jump to

Keyboard shortcuts

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