logger

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2026 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Overview

Package logger provides a preinitialized slog logger ready for use.

Additionally it provides middlewares for use with http handlers to record access logs.

Index

Constants

View Source
const (
	LevelTrace       slog.Level = -8
	LevelTraceString            = "TRACE"
)
View Source
const MaximumValueLength = 2000

Variables

This section is empty.

Functions

func AccessLogMiddleware

func AccessLogMiddleware(next http.Handler) http.Handler

func ContextWithAttr

func ContextWithAttr(parent context.Context, attr slog.Attr) context.Context

ContextWithAttr returns a copy of parent in which the attr is added to the list of slog attributes attached to the context.

Use context slog attributes only for request-scoped log attributes.

func Err

func Err(err error) slog.Attr

Err is a helper function to ensure errors are always logged with the key "err". Additionally this becomes the single point in code, where we could tweak how errors are logged, e.g. to handle application specific error types or to add stack trace information in debug mode.

func InitLogger

func InitLogger(writer io.Writer, filepath string, verbose bool, debug bool) error

func ParseLevel

func ParseLevel(levelStr string) slog.Level

ParseLevel converts a given string representation for a log level into an actual slog.Level. Defaults to log level warn.

func RequestIDMiddleware

func RequestIDMiddleware(next http.Handler) http.Handler

func SetLogLevel

func SetLogLevel(level slog.Level) error

SetLogLevel replaces the default logger with a logger of the given log level.

func ValidateLevel

func ValidateLevel(levelStr string) error

ValidateLevel checks a given string representation for a log level against the supported log levels.

Types

This section is empty.

Jump to

Keyboard shortcuts

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