A simple logger hook for bun ORM using Go's slog package. It logs SQL queries, errors, and slow queries with flexible configuration. 🚀
- 🐞 Log all queries
- 🎚️ Custom log levels for queries, errors, and slow queries
- ⚙️ Environment variable configuration
- 🔗 Integrates with Go's
sloglogger
go get github.com/XanderD99/bunslogpackage main
import (
"context"
"log/slog"
"os"
"time"
"github.com/uptrace/bun"
"github.com/XanderD99/bunslog"
)
func main() {
db := bun.NewDB(/* ... */)
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
hook := bunslog.NewQueryHook(
bunslog.WithLogger(logger),
bunslog.WithLogSlow(100 * time.Millisecond), // log queries slower than 100ms
)
db.AddQueryHook(hook)
// ... your queries ...
}You can control logging via environment variables:
- 📴
BUNDEBUG=0disables logging - ✅
BUNDEBUG=1enables logging
MIT 🎉