slogging

Everything for Go's stdlib log/slog in one place: configure it from the environment, and stack handlers onto it that ship logs to Loki or keep them searchable in memory.
Spiritual successor to logrus-configurator, and the continuation of slog-configurator. Coming from there? Read Migrating from slog-configurator.
Contents
Documentation
The full documentation lives at psyb0t.github.io/slogging.
| Page |
Covers |
| Configuring slog |
LOG_LEVEL, LOG_FORMAT, LOG_ADD_SOURCE, renaming them, and AddSink vs SetOutput vs SetHandlers |
| Output and fan-out handlers |
The stdout and stderr split, several writers per stream, a level you can change at runtime, teeing to many handlers |
| Searchable ring |
The in-memory ring: limits, attribute search, paging, stats |
| Loki handler |
Settings, labels, line format, and what happens when Loki is down |
| Troubleshooting |
The startup panic, doubled lines, sinks that see nothing, missing Loki records |
| Migrating from slog-configurator |
Old import paths and the pre-1.7 handler API |
| Development |
Make targets, tests, CI and releases |
Quick start
go get github.com/psyb0t/slogging
package main
import (
"log/slog"
_ "github.com/psyb0t/slogging/slogconf" // configures slog at init time
)
func main() {
slog.Info("this is an info message", "user", "psyb0t", "action", "testing")
slog.Error("this is an error message", "error_code", "E001")
}
export LOG_LEVEL="debug" # debug / info / warn / error
export LOG_FORMAT="json" # json / text
export LOG_ADD_SOURCE="true" # include source file/line/function
go run main.go
stdout/stderr are split automatically. Info and debug go to stdout, warnings and errors to stderr. Container log collectors capture both and tag them, so error noise stays separate from happy-path noise.
Need more than the blank import? Rename the variables with slogconf.Init, add a destination with slogconf.AddSink, or swap where you print with slogconf.SetOutput. Those are different calls on purpose, and Configuring slog explains why.
Layout
slogconf/ configure slog from the environment
handlers/ Handler (the process's output) + FanOutHandler (tees to many)
handlers/logring/ bounded in-memory ring you can search
handlers/loki/ push records to Loki's HTTP API
Two kinds of thing live here, and the split is the whole design. handlers holds the structural pieces: the one that writes your output, and the one that tees a record to many. Its subpackages are destinations: a searchable ring, a Loki server. You configure one output and add as many destinations as you like.
Runtime dependencies are ctxerrors and nothing else. No config loader, no HTTP framework. Every handler talks to log/slog and the standard library.
Development
make test # all tests with -race
make test-coverage # coverage gate (fails under 90%)
make lint # go fix + golangci-lint
make lint-fix # same, with --fix
make docs # build the docs site locally with Docker
See make help for the full list and Development for CI and releases.

License
MIT. See LICENSE.
See CHANGELOG.md for release notes.