Skip to content

comsma/zerobun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Reference Go Report Card

zerobun

Zerobun is a query hook for uptrace/bun that logs with rs/zerolog

go get -u github.com/comsma/zerobun

Usage

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,
			},
		),
	)
}

Example Output

{ "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"}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages