// setup your logger
w := zerolog.NewConsolewriter()
w.Out = os.Stdout
log.Logger = zerolog.New(w).Level(zerolog.InfoLevel)
// setup gorm
db, _ := gorm.Open(sqlite.Open(":memory:"), &gorm.Config{
Logger: &gorm0log.Logger{
Logger: log.Logger,
Config: Config{
SlowThreshold: 3 * time.Second, // log sql queries slower than 3s
ErrorLevel: gorm0log.DebugCommonErr, // log common errors at debug level
ParameterizedQueries: true, // do not log value of parameters
},
},
})
db.Debug().Save(&User{Name: "John Doe"}) // dumps sql
var u User
db.Where("id", -1).Find(&user) // record not found, but ignored
db.Debug().Where("id", -1).Find(&user) // record not found error is logged
var x NonExistTable
db.Where("id", 1).Find(&x) // logs error
Mozilla Public License, v. 2.0