feat: add cli switch fx-debug to disable our custom logger

This commit is contained in:
Derrick Hammer 2024-01-30 17:45:36 -05:00
parent 57c4a1ae7d
commit 2de10a7401
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 25 additions and 9 deletions

View File

@ -9,10 +9,13 @@ import (
_logger "git.lumeweb.com/LumeWeb/portal/logger"
"git.lumeweb.com/LumeWeb/portal/protocols"
"git.lumeweb.com/LumeWeb/portal/storage"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
"go.uber.org/fx"
"go.uber.org/fx/fxevent"
_ "go.uber.org/fx/fxevent"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
_ "go.uber.org/zap/zapcore"
"net/http"
)
@ -26,9 +29,27 @@ func main() {
logger.Fatal("Failed to load config", zap.Error(err))
}
var fxDebug bool
flag.BoolVar(&fxDebug, "fx-debug", false, "Enable fx framework debug logging")
flag.Parse()
protocols.RegisterProtocols()
api.RegisterApis()
var fxLogger fx.Option
fxLogger = fx.WithLogger(func(logger *zap.Logger) fxevent.Logger {
log := &fxevent.ZapLogger{Logger: logger}
log.UseLogLevel(zapcore.InfoLevel)
log.UseErrorLevel(zapcore.ErrorLevel)
return log
})
if fxDebug {
fxLogger = fx.Options()
}
fx.New(
fx.Provide(_logger.NewFallbackLogger),
fx.Provide(func() *viper.Viper {
@ -37,13 +58,8 @@ func main() {
fx.Decorate(func() *zap.Logger {
return logger
}),/*
fx.WithLogger(func(logger *zap.Logger) fxevent.Logger {
log := &fxevent.ZapLogger{Logger: logger}
log.UseLogLevel(zapcore.InfoLevel)
log.UseErrorLevel(zapcore.ErrorLevel)
return log
}),*/
}),
fxLogger,
fx.Invoke(initCheckRequiredConfig),
fx.Provide(NewIdentity),
db.Module,