From ebb4971b8d790fd3fe2b77a22103f149e7dcec44 Mon Sep 17 00:00:00 2001 From: Sebastian Choren Date: Mon, 2 Sep 2024 15:06:23 -0300 Subject: [PATCH] fix(cli): fix logger setup --- agent/runner/runner.go | 29 +---------------------------- cli/cmd/config.go | 2 ++ cli/cmd/start_cmd.go | 2 +- 3 files changed, 4 insertions(+), 29 deletions(-) diff --git a/agent/runner/runner.go b/agent/runner/runner.go index f134509586..d02d455192 100644 --- a/agent/runner/runner.go +++ b/agent/runner/runner.go @@ -3,7 +3,6 @@ package runner import ( "context" "errors" - "fmt" "os" "github.com/golang-jwt/jwt" @@ -16,7 +15,6 @@ import ( "github.com/kubeshop/tracetest/cli/pkg/resourcemanager" "go.uber.org/zap" - "go.uber.org/zap/zapcore" ) type Runner struct { @@ -39,7 +37,7 @@ func NewRunner(configurator config.Configurator, resources *resourcemanager.Regi } } -func (s *Runner) Run(ctx context.Context, cfg config.Config, flags agentConfig.Flags, verbose bool) error { +func (s *Runner) Run(ctx context.Context, logger *zap.Logger, cfg config.Config, flags agentConfig.Flags, verbose bool) error { s.ui.Banner(config.Version) s.ui.Println(`Tracetest start launches a lightweight agent. It enables you to run tests and collect traces with Tracetest. Once started, Tracetest Agent exposes OTLP ports 4317 and 4318 to ingest traces via gRCP and HTTP.`) @@ -52,31 +50,6 @@ Once started, Tracetest Agent exposes OTLP ports 4317 and 4318 to ingest traces s.mode = flags.Mode s.ui.Infof("Running in %s mode...", s.mode) - logger := zap.NewNop() - - if enableLogging(flags.LogLevel) { - var err error - atom := zap.NewAtomicLevel() - if verbose { - atom.SetLevel(zapcore.DebugLevel) - } - - logger, err = zap.NewDevelopment() - if err != nil { - return fmt.Errorf("could not create logger: %w", err) - } - - logger = logger.WithOptions(zap.WrapCore(func(c zapcore.Core) zapcore.Core { - return zapcore.NewCore( - zapcore.NewJSONEncoder(zap.NewDevelopmentEncoderConfig()), - zapcore.Lock(os.Stdout), - atom, - ) - })) - - s.loggerLevel = &atom - } - s.logger = logger s.configurator = s.configurator.WithLogger(logger) oauth.SetLogger(logger) diff --git a/cli/cmd/config.go b/cli/cmd/config.go index ca35f3e04f..5c7f992534 100644 --- a/cli/cmd/config.go +++ b/cli/cmd/config.go @@ -10,6 +10,7 @@ import ( "github.com/kubeshop/tracetest/cli/config" "github.com/kubeshop/tracetest/cli/formatters" "github.com/kubeshop/tracetest/cli/openapi" + "github.com/kubeshop/tracetest/cli/pkg/oauth" "github.com/spf13/cobra" "go.uber.org/zap" ) @@ -132,6 +133,7 @@ func validateConfig(cmd *cobra.Command, args []string) { func setupLogger(cmd *cobra.Command, args []string) { l := cmdutil.GetLogger(cmdutil.WithVerbose(verbose)) *cliLogger = *l + oauth.SetLogger(l) } func teardownCommand(cmd *cobra.Command, args []string) { diff --git a/cli/cmd/start_cmd.go b/cli/cmd/start_cmd.go index c6d612c7b8..d6de2a2d70 100644 --- a/cli/cmd/start_cmd.go +++ b/cli/cmd/start_cmd.go @@ -76,7 +76,7 @@ var startCmd = &cobra.Command{ cfg.EnvironmentID = flags.EnvironmentID } - err = agentRunner.Run(ctx, cliConfig, flags, verbose) + err = agentRunner.Run(ctx, cliLogger, cliConfig, flags, verbose) return "", err })), PostRun: teardownCommand,