From 536f7c044327a8f1432c1c1ec7a870e063c8a9f1 Mon Sep 17 00:00:00 2001 From: soxx Date: Fri, 21 Jun 2024 23:48:18 +0200 Subject: [PATCH] fix(postgres): Update database logger in postgres.go to include slow queries and error handling Signed-off-by: soxx --- pkg/database/postgres.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/database/postgres.go b/pkg/database/postgres.go index ab22d85..ff4eb16 100644 --- a/pkg/database/postgres.go +++ b/pkg/database/postgres.go @@ -15,6 +15,9 @@ import ( gormPostgres "gorm.io/driver/postgres" "gorm.io/gorm" logger2 "gorm.io/gorm/logger" + log2 "log" + "os" + "time" ) //go:embed migrations/*.sql @@ -43,8 +46,15 @@ func (p *postgresqlConnection) Connect(_ context.Context, endpoint string, usern log.Infof("OtterSpace: migration compleate") + dbLogger := logger2.New(log2.New(os.Stdout, "\r\n", log2.LstdFlags), logger2.Config{ + SlowThreshold: 200 * time.Millisecond, + LogLevel: logger2.Warn, + IgnoreRecordNotFoundError: true, + Colorful: true, + }) + db, err := gorm.Open(gormPostgres.Open(dsn), &gorm.Config{ - Logger: logger2.Default.LogMode(logger2.Silent), + Logger: dbLogger, }) p.db = db if err != nil {