Skip to content

falmar/slogger

Repository files navigation

slogger

Minimal wrapper around log/slog for creating configured loggers and propagating them through context.

Install

go get github.com/falmar/slogger

Usage

package main

import (
	"log/slog"

	"github.com/falmar/slogger"
)

func main() {
	// Default logger (text, stderr, info level)
	logger := slogger.New()

	// Custom config
	logger = slogger.New(slogger.Config{
		Format: slogger.FormatJSON,
		Level:  slog.LevelDebug,
	})

	// Store in context
	ctx := slogger.WithLogger(context.Background(), logger)

	// Retrieve from context
	logger = slogger.FromContext(ctx)
	logger.Info("hello")
}

License

MIT

About

Tiny wrapper around slog

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages