Skip to content

Commit

Permalink
db logger: error level
Browse files Browse the repository at this point in the history
  • Loading branch information
kiwiidb committed Jul 11, 2023
1 parent ca709a9 commit bf9c635
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions db.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"log"
"os"
"time"

"github.com/lightningnetwork/lnd/lnrpc"
Expand All @@ -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
Expand Down

0 comments on commit bf9c635

Please sign in to comment.