From 29b80e3ca16aeb5818e0e6a4d540be8f336bc7cd Mon Sep 17 00:00:00 2001 From: Juan Font Alonso Date: Sun, 11 Jul 2021 13:13:36 +0200 Subject: [PATCH] Fix debug mode enabled by default in db --- db.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/db.go b/db.go index 99d45f86..6a057e16 100644 --- a/db.go +++ b/db.go @@ -6,6 +6,7 @@ import ( "gorm.io/driver/postgres" "gorm.io/driver/sqlite" "gorm.io/gorm" + "gorm.io/gorm/logger" ) const dbVersion = "1" @@ -50,23 +51,31 @@ func (h *Headscale) initDB() error { func (h *Headscale) openDB() (*gorm.DB, error) { var db *gorm.DB var err error + + var log logger.Interface + if h.dbDebug { + log = logger.Default + } else { + log = logger.Default.LogMode(logger.Silent) + } + switch h.dbType { case "sqlite3": db, err = gorm.Open(sqlite.Open(h.dbString), &gorm.Config{ DisableForeignKeyConstraintWhenMigrating: true, + Logger: log, }) case "postgres": db, err = gorm.Open(postgres.Open(h.dbString), &gorm.Config{ DisableForeignKeyConstraintWhenMigrating: true, + Logger: log, }) } if err != nil { return nil, err } - if h.dbDebug { - db.Debug() - } + return db, nil }