1
0
mirror of https://github.com/muety/wakapi.git synced 2023-08-10 21:12:56 +03:00

chore: stop gorm from logging queries

This commit is contained in:
Ferdinand Mütsch 2021-01-31 18:29:24 +01:00
parent 0c3f3b37b0
commit f483488dd5

15
main.go
View File

@ -9,6 +9,7 @@ import (
conf "github.com/muety/wakapi/config" conf "github.com/muety/wakapi/config"
"github.com/muety/wakapi/migrations/common" "github.com/muety/wakapi/migrations/common"
"github.com/muety/wakapi/repositories" "github.com/muety/wakapi/repositories"
"gorm.io/gorm/logger"
"log" "log"
"net/http" "net/http"
"os" "os"
@ -65,9 +66,19 @@ func main() {
logbuch.SetLevel(logbuch.LevelInfo) logbuch.SetLevel(logbuch.LevelInfo)
} }
// Set up GORM
gormLogger := logger.New(
log.New(os.Stdout, "", log.LstdFlags),
logger.Config{
SlowThreshold: time.Minute,
Colorful: false,
LogLevel: logger.Silent,
},
)
// Connect to database // Connect to database
var err error var err error
db, err = gorm.Open(config.Db.GetDialector(), &gorm.Config{}) db, err = gorm.Open(config.Db.GetDialector(), &gorm.Config{Logger: gormLogger})
if config.Db.Dialect == "sqlite3" { if config.Db.Dialect == "sqlite3" {
db.Raw("PRAGMA foreign_keys = ON;") db.Raw("PRAGMA foreign_keys = ON;")
} }
@ -144,7 +155,7 @@ func main() {
recoveryMiddleware := handlers.RecoveryHandler() recoveryMiddleware := handlers.RecoveryHandler()
loggingMiddleware := middlewares.NewLoggingMiddleware( loggingMiddleware := middlewares.NewLoggingMiddleware(
// Use logbuch here once https://github.com/emvi/logbuch/issues/4 is realized // Use logbuch here once https://github.com/emvi/logbuch/issues/4 is realized
log.New(os.Stdout, "", 0), log.New(os.Stdout, "", log.LstdFlags),
) )
corsMiddleware := handlers.CORS() corsMiddleware := handlers.CORS()
authenticateMiddleware := middlewares.NewAuthenticateMiddleware( authenticateMiddleware := middlewares.NewAuthenticateMiddleware(