feat: add debug mode logging support

This commit is contained in:
Derrick Hammer 2023-06-06 16:37:22 -04:00
parent 670bc9d64c
commit 99d7b8347a
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
2 changed files with 10 additions and 1 deletions

View File

@ -25,6 +25,7 @@ func Init() {
pflag.String("database.name", "lumeweb_portal", "Database name") pflag.String("database.name", "lumeweb_portal", "Database name")
pflag.String("database.path", "./db.sqlite", "Database path for SQLite") pflag.String("database.path", "./db.sqlite", "Database path for SQLite")
pflag.String("renterd-api-password", ".", "admin password for renterd") pflag.String("renterd-api-password", ".", "admin password for renterd")
pflag.Bool("debug", false, "enable debug mode")
pflag.Parse() pflag.Parse()
err := viper.BindPFlags(pflag.CommandLine) err := viper.BindPFlags(pflag.CommandLine)

View File

@ -1,6 +1,7 @@
package logger package logger
import ( import (
"github.com/spf13/viper"
"go.uber.org/zap" "go.uber.org/zap"
"log" "log"
) )
@ -8,7 +9,14 @@ import (
var logger *zap.Logger var logger *zap.Logger
func Init() { 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 { if err != nil {
log.Fatal(err) log.Fatal(err)