pkg/log/gorm.go

19 lines
335 B
Go
Raw Permalink Normal View History

2023-09-18 15:51:20 +08:00
package log
import (
"go.uber.org/zap"
"gorm.io/gorm/logger"
"moul.io/zapgorm2"
)
func GormZapLogger(debug bool) logger.Interface {
l := zapgorm2.New(zap.L())
if !debug {
l.LogLevel = -1
} else {
l.LogLevel = logger.Info
}
l.SetAsDefault() // optional: configure gorm to use this zapgorm.Logger for callbacks
return l
}