From 99d7b8347af25fe65a1f1aecc9960424a101c279 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 6 Jun 2023 16:37:22 -0400 Subject: [PATCH] feat: add debug mode logging support --- config/config.go | 1 + logger/logger.go | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index f69351c..32bdeee 100644 --- a/config/config.go +++ b/config/config.go @@ -25,6 +25,7 @@ func Init() { pflag.String("database.name", "lumeweb_portal", "Database name") pflag.String("database.path", "./db.sqlite", "Database path for SQLite") pflag.String("renterd-api-password", ".", "admin password for renterd") + pflag.Bool("debug", false, "enable debug mode") pflag.Parse() err := viper.BindPFlags(pflag.CommandLine) diff --git a/logger/logger.go b/logger/logger.go index 0bfa2f8..72391c0 100644 --- a/logger/logger.go +++ b/logger/logger.go @@ -1,6 +1,7 @@ package logger import ( + "github.com/spf13/viper" "go.uber.org/zap" "log" ) @@ -8,7 +9,14 @@ import ( var logger *zap.Logger func Init() { - newLogger, err := zap.NewProduction() + var newLogger *zap.Logger + var err error + + if viper.GetBool("debug") { + newLogger, err = zap.NewDevelopment() + } else { + newLogger, err = zap.NewProduction() + } if err != nil { log.Fatal(err)