Fix: Move database logging to stderr

to prevent parsing errors to break the bot response

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2024-03-24 13:56:08 +01:00
parent 81766ac5df
commit 46dbb7049c
Signed by: luzifer
SSH Key Fingerprint: SHA256:/xtE5lCgiRDQr8SLxHMS92ZBlACmATUmF1crK16Ks4E
1 changed files with 10 additions and 0 deletions

View File

@ -2,12 +2,16 @@ package database
import (
"fmt"
"log"
"os"
"time"
"github.com/glebarez/sqlite"
"github.com/pkg/errors"
"gorm.io/driver/mysql"
"gorm.io/driver/postgres"
"gorm.io/gorm"
"gorm.io/gorm/logger"
)
type (
@ -36,6 +40,12 @@ func New(driverName, connString string) (d *DB, err error) {
db, err := gorm.Open(innerDB, &gorm.Config{
DisableForeignKeyConstraintWhenMigrating: true,
Logger: logger.New(log.New(os.Stderr, "\r\n", log.LstdFlags), logger.Config{
SlowThreshold: time.Second,
LogLevel: logger.Warn,
IgnoreRecordNotFoundError: true,
Colorful: false,
}),
})
if err != nil {
return nil, errors.Wrap(err, "connecting database")