log is a leveled, multi-output logging package for Go. A single log call fans
out to every configured output, and each output independently decides which
levels it accepts, whether it renders text or JSON, whether it uses colour, and
how the message prefix is laid out.
It is safe for concurrent use, and work is skipped when nobody needs it: level filtering happens at the source, and stack-frame capture and formatting run only when at least one output requires them, so silent levels stay cheap.
- Seven levels —
Panic,Fatal,Error,Warn,Info,Debug,Trace, each with plain /…f/…lnforms. - Multiple outputs — console, files and custom writers at once, each with per-output level filtering, text or JSON, ANSI colour and a configurable prefix layout.
- Thread-safe — mutex-protected, with buffer pooling on the hot path.
slogbridge — back the standardlog/slogwithNewSlogorlogger.Handler().- Ad-hoc writers — the
F-family also tees a message to a one-off writer. - Observability —
Enabledguards expensive work;SetErrorHandlersurfaces failing outputs.
go get -u github.com/goloop/log/v2import "github.com/goloop/log/v2"Requires Go 1.24 or newer.
package main
import "github.com/goloop/log/v2"
func main() {
logger := log.New("APP")
logger.Info("Application started")
logger.Infof("User %s logged in", "bob")
logger.Errorln("Failed to connect to database")
}Fan out to a coloured console and a JSON file, each filtered by level:
import (
"github.com/goloop/log/v2"
"github.com/goloop/log/v2/layout"
"github.com/goloop/log/v2/level"
)
log.SetOutputs(
log.Output{
Name: "console",
Writer: os.Stdout,
Levels: level.Info | level.Warn | level.Error,
Layouts: layout.Default,
WithColor: 1,
TextStyle: 1,
},
log.Output{
Name: "file",
Writer: file,
Levels: level.Error | level.Fatal,
TextStyle: -1, // JSON
},
)
log.Info("System initialized")
log.Error("Database connection failed")Back the standard log/slog:
slogger := log.NewSlog("APP")
slogger.Info("user logged in", "user", "bob", "id", 42)- Full reference and recipes: DOC.md · DOC.UK.md
- Package API: pkg.go.dev/github.com/goloop/log/v2
- Changes between versions: CHANGELOG.md
Contributions are welcome. Please run go test ./..., go vet ./... and
gofmt -l . before submitting a pull request.
log is released under the MIT License. See LICENSE.