Logging queries
Then add the provided query hook which by default only prints failed queries:
import "github.com/uptrace/bun/extra/bundebug"
db := bun.NewDB(sqldb, dialect)
You can also disable the hook by default and use environment variables to enable it when needed:
// disable the hook
bundebug.WithEnabled(false),
// BUNDEBUG=1 logs failed queries
)
Logrus hook
Use QueryHookOptions
to adjust log levels and behavior:
db := bun.NewDB(sqldb, dialect)
log := logrus.New()