slogutil

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2025 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package slogutil provides configuration and setup utilities for slog.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidFormat = errors.New("invalid log format")

ErrInvalidFormat is returned when Format contains an unrecognized value.

View Source
var ErrInvalidLevel = errors.New("invalid log level")

ErrInvalidLevel is returned when Level contains an unrecognized value.

Functions

func Setup

func Setup(cfg Config) error

Setup configures the global slog logger based on cfg. It sets slog.SetDefault() with the configured handler writing to os.Stderr. Returns error if Level or Format contains invalid values.

Types

type Config

type Config struct {
	// Level is the minimum log level.
	// Valid values: "debug", "info", "warn", "warning", "error".
	// Default: "info"
	Level string `koanf:"level"`

	// Format is the output format.
	// Valid values: "text", "json".
	// Default: "text"
	Format string `koanf:"format"`
}

Config holds configuration for slog setup.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a Config with sensible defaults.

Jump to

Keyboard shortcuts

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