From 34899a883011b4f5e5ae5785e855f9c32ed6c3ca Mon Sep 17 00:00:00 2001 From: Vishwas Shashidhar Date: Thu, 13 Apr 2023 08:32:55 +0530 Subject: [PATCH] configure logging for gorm manager --- database/gorm_manager.go | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/database/gorm_manager.go b/database/gorm_manager.go index 3bb60e3..2db6716 100644 --- a/database/gorm_manager.go +++ b/database/gorm_manager.go @@ -2,12 +2,16 @@ package database import ( "fmt" + "log" + "os" "strconv" "strings" + "time" "github.com/jackc/pgconn" "gorm.io/driver/postgres" "gorm.io/gorm" + gLogger "gorm.io/gorm/logger" "gorm.io/plugin/dbresolver" "github.com/adwitiyaio/arka/constants" @@ -77,7 +81,20 @@ func (gdm gormDatabaseManager) connect() *gorm.DB { dsn := fmt.Sprintf("host=%s user=%s password=%s dbname=%s port=%d sslmode=disable", host, user, password, database, port) - db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{}) + gormLogger := gLogger.New( + log.New(os.Stdout, "\r\n", log.LstdFlags), + gLogger.Config{ + SlowThreshold: time.Second, + LogLevel: gLogger.Silent, + IgnoreRecordNotFoundError: true, + ParameterizedQueries: true, + Colorful: false, + }, + ) + + db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{ + Logger: gormLogger, + }) if err != nil { logger.Log.Panic().Err(err).Stack().Msg("unable to connect to database")