logging

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package logging builds the application's structured logger on top of the standard library's log/slog. The composition root constructs a *slog.Logger with New and injects it into the components that need it (dependency inversion: there is no package-level logger and slog.SetDefault is never called, so logging is an explicit dependency rather than ambient global state).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(cfg Config) *slog.Logger

New builds a *slog.Logger that writes JSON records — including the source file:line — at or above cfg.Level to cfg.Writer.

func ParseLevel

func ParseLevel(s string) (slog.Level, error)

ParseLevel maps a level name to a slog.Level, case-insensitively and ignoring surrounding whitespace. An empty string defaults to Info with no error (an unset env var is not a misconfiguration). "warning" is accepted as an alias for "warn". An unrecognized non-empty value returns Info plus a *LevelError so the caller can fall back safely while still surfacing the typo.

Types

type Config

type Config struct {
	// Writer is the destination for log records. A nil Writer is treated as
	// io.Discard so a misconfiguration drops logs rather than panicking on first use.
	Writer io.Writer
	// Level is the minimum severity emitted; records below it are dropped.
	Level slog.Level
}

Config configures a logger built by New.

type LevelError

type LevelError struct {
	Value string
}

LevelError reports a log-level string that ParseLevel did not recognize.

func (*LevelError) Error

func (e *LevelError) Error() string

Error implements error.

Jump to

Keyboard shortcuts

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