slog Handlers
Text and JSON handlers.
Handlers Decide the Format
In slog, a Logger calls a Handler to format and write each record. Swapping the handler changes the output format without touching your log calls.
TextHandler
slog.NewTextHandler writes human-friendly key=value lines. Good for local development and terminals.
package main
import (
"log/slog"
"os"
)
func main() {
h := slog.NewTextHandler(os.Stdout, nil)
logger := slog.New(h)
logger.Info("hello", "env", "dev")
}