Open sysmat opened 1 year ago
Hello 👋 thank you for raising an issue and sorry for the response time 🤦
Gorm does not offers a "Debug" log level, to start the Debug mode on gorm you need to use the Debug
function. I did a full example here to test if it works:
package main
import (
"fmt"
"os"
log "github.com/sirupsen/logrus"
gormv2logrus "github.com/thomas-tacquet/gormv2-logrus"
"gorm.io/driver/sqlite"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
func main() {
lrus := log.New()
lrus.SetFormatter(&log.JSONFormatter{})
lrus.SetOutput(os.Stdout)
lrus.SetLevel(log.TraceLevel)
gormLog := gormv2logrus.NewGormlog(
gormv2logrus.WithLogrus(lrus),
gormv2logrus.WithGormOptions(
gormv2logrus.GormOptions{
LogLevel: logger.Info,
LogLatency: true,
},
),
)
const sqliteConnString = "file:%s?mode=memory&cache=shared"
db, err := gorm.Open(sqlite.Open(
fmt.Sprintf(sqliteConnString, "testing")),
&gorm.Config{Logger: gormLog},
)
if err != nil {
panic(err)
}
_ = db.Debug().Exec(`SELECT printf('This is an information message.');`)
if err != nil {
log.Fatal(err)
}
}
``
logger.Default.LogMode(logger.Silent)
it works fine, but output is console