Skip to content

Commit

Permalink
configure logging for gorm manager
Browse files Browse the repository at this point in the history
  • Loading branch information
Vishwas Shashidhar committed Apr 13, 2023
1 parent 1eb9491 commit 34899a8
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion database/gorm_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 34899a8

Please sign in to comment.