From 2de10a74012f3e7bc5b5a24ded6d5248fbf24174 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Tue, 30 Jan 2024 17:45:36 -0500 Subject: [PATCH] feat: add cli switch fx-debug to disable our custom logger --- cmd/portal/main.go | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/cmd/portal/main.go b/cmd/portal/main.go index c72658a..7628506 100644 --- a/cmd/portal/main.go +++ b/cmd/portal/main.go @@ -9,11 +9,14 @@ 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/fx/fxevent" "go.uber.org/zap" - _"go.uber.org/zap/zapcore" + "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,