Alternative logging with zerolog for GORM ⚡️
In comparison to gorm's default logger, gorm-zerolog
is faster, reflection free, low allocations and no regex
compilations.
package main
import (
"github.com/jinzhu/gorm"
"github.com/gorpher/gorm-zerolog"
)
const (
databaseURL = "postgres://postgres:@localhost/gormzr?sslmode=disable"
)
func main() {
logger, err = zerolog.NewProduction()
if err != nil {
panic(err)
}
db, err := gorm.Open("postgres", databaseURL)
if err != nil {
panic(err)
}
db.LogMode(true)
db.SetLogger(gorm - zerolog.New(logger))
// ...
}