feat: add debug mode logging support
This commit is contained in:
parent
670bc9d64c
commit
99d7b8347a
|
@ -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)
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue