This lib allows to simply create a Golang structured logger with its handler automatically selected:
- If the output is a terminal, a standard text handler will be used
- If the program has been started by systemd, a custom journald handler will be used
- Otherwise a standard JSON handler will be used
go get -u github.com/iguanesolutions/auto-slog
package main
import (
"log/slog"
autoslog "github.com/iguanesolutions/auto-slog"
)
func main() {
logger := autoslog.NewLogger(autoslog.LogLevel("INFO"))
logger.Info("Hello !", slog.Any("key", "value"))
}