diff --git a/db.go b/db.go index 31febc9..e795ad7 100644 --- a/db.go +++ b/db.go @@ -1,6 +1,8 @@ package main import ( + "log" + "os" "time" "github.com/lightningnetwork/lnd/lnrpc" @@ -10,13 +12,20 @@ import ( ) func OpenDB(config *Config) (db *gorm.DB, err error) { - db, err = gorm.Open(postgres.Open(config.DatabaseUri), &gorm.Config{}) + //overwrite logger so we don't print warnings for slow sql + //because we use db transactions that span the rabbitmq publish operation + dbLogger := logger.New(log.New(os.Stdout, "\r\n", log.LstdFlags), logger.Config{ + SlowThreshold: 200 * time.Millisecond, + LogLevel: logger.Error, + IgnoreRecordNotFoundError: false, + Colorful: true, + }) + db, err = gorm.Open(postgres.Open(config.DatabaseUri), &gorm.Config{ + Logger: dbLogger, + }) if err != nil { return nil, err } - //don't print warnings for slow sql - //because we use db transactions that span the rabbitmq publish operation - db.Logger.LogMode(logger.Error) sqlDB, err := db.DB() if err != nil { return nil, err