Zerobun is a query hook for uptrace/bun that logs with rs/zerolog
go get -u github.com/comsma/zerobun
package main
import (
"os"
"github.com/rs/zerolog"
"github.com/uptrace/bun"
)
func main() {
logger := zerolog.New(os.Stderr).With().Timestamp().Logger()
db := bun.NewDb()
db.AddQueryHook(
zerobun.NewQueryHook(
zerobun.QueryHookOptions{
SlowDuration: 5,
Logger: &logger,
},
),
)
}
{ "level":"error",
"bun_info":{
"operation":"SELECT",
"operation_time_ms":0,
"query":"SELECT * FROM products WHERE ID = 5",
},
"error":"database error",
"time":"2023-11-15T16:12:24-05:00"}