Integrate GORM Logger with Zerolog and Add Configuration Options for Logging and Performance (#2040)

* Integrate GORM logger with zerolog and add custom GORM configuration options

* Add GormConfig struct to group GORM-related settings

* Update debug mode instruction in config-example.yaml

Co-authored-by: Kristoffer Dalby <kristoffer@dalby.cc>

---------

Co-authored-by: Kristoffer Dalby <kristoffer@dalby.cc>
This commit is contained in:
nadongjun 2024-08-19 18:47:52 +09:00 committed by GitHub
parent ac8491efec
commit fdc034e8ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 118 additions and 2 deletions

View file

@ -426,7 +426,7 @@ func openDB(cfg types.DatabaseConfig) (*gorm.DB, error) {
// TODO(kradalby): Integrate this with zerolog
var dbLogger logger.Interface
if cfg.Debug {
dbLogger = logger.Default
dbLogger = util.NewDBLogWrapper(&log.Logger, cfg.Gorm.SlowThreshold, cfg.Gorm.SkipErrRecordNotFound, cfg.Gorm.ParameterizedQueries)
} else {
dbLogger = logger.Default.LogMode(logger.Silent)
}
@ -447,7 +447,8 @@ func openDB(cfg types.DatabaseConfig) (*gorm.DB, error) {
db, err := gorm.Open(
sqlite.Open(cfg.Sqlite.Path),
&gorm.Config{
Logger: dbLogger,
PrepareStmt: cfg.Gorm.PrepareStmt,
Logger: dbLogger,
},
)