diff --git a/pkg/cloud/aws/commands/run.go b/pkg/cloud/aws/commands/run.go index a4541e9f0544..23406aeafda5 100644 --- a/pkg/cloud/aws/commands/run.go +++ b/pkg/cloud/aws/commands/run.go @@ -132,10 +132,6 @@ func Run(ctx context.Context, opt flag.Options) error { ctx, cancel := context.WithTimeout(ctx, opt.GlobalOptions.Timeout) defer cancel() - if err := log.InitLogger(opt.Debug, false); err != nil { - return xerrors.Errorf("logger error: %w", err) - } - var err error defer func() { if errors.Is(err, context.DeadlineExceeded) { diff --git a/pkg/cloud/aws/scanner/progress.go b/pkg/cloud/aws/scanner/progress.go index 243e6eb47f39..a313dd482c6c 100644 --- a/pkg/cloud/aws/scanner/progress.go +++ b/pkg/cloud/aws/scanner/progress.go @@ -2,6 +2,7 @@ package scanner import ( "fmt" + "io" "os" "github.com/aquasecurity/loading/pkg/bar" @@ -12,15 +13,17 @@ type progressTracker struct { serviceTotal int serviceCurrent int isTTY bool + debugWriter io.Writer } -func newProgressTracker() *progressTracker { +func newProgressTracker(w io.Writer) *progressTracker { var isTTY bool if stat, err := os.Stdout.Stat(); err == nil { isTTY = stat.Mode()&os.ModeCharDevice == os.ModeCharDevice } return &progressTracker{ - isTTY: isTTY, + isTTY: isTTY, + debugWriter: w, } } @@ -69,7 +72,8 @@ func (m *progressTracker) StartService(name string) { if !m.isTTY { return } - fmt.Printf("[%d/%d] Scanning %s...\n", m.serviceCurrent+1, m.serviceTotal, name) + + fmt.Fprintf(m.debugWriter, "[%d/%d] Scanning %s...\n", m.serviceCurrent+1, m.serviceTotal, name) m.serviceBar = bar.New( bar.OptionHideOnFinish(true), bar.OptionWithAutoComplete(false), diff --git a/pkg/cloud/aws/scanner/scanner.go b/pkg/cloud/aws/scanner/scanner.go index d91721512505..97f544492747 100644 --- a/pkg/cloud/aws/scanner/scanner.go +++ b/pkg/cloud/aws/scanner/scanner.go @@ -31,9 +31,11 @@ func (s *AWSScanner) Scan(ctx context.Context, option flag.Options) (scan.Result awsCache := cache.New(option.CacheDir, option.MaxCacheAge, option.Account, option.Region) included, missing := awsCache.ListServices(option.Services) + prefixedLogger := &log.PrefixedLogger{Name: "aws"} + var scannerOpts []options.ScannerOption if !option.NoProgress { - tracker := newProgressTracker() + tracker := newProgressTracker(prefixedLogger) defer tracker.Finish() scannerOpts = append(scannerOpts, aws.ScannerWithProgressTracker(tracker)) } @@ -43,11 +45,11 @@ func (s *AWSScanner) Scan(ctx context.Context, option flag.Options) (scan.Result } if option.Debug { - scannerOpts = append(scannerOpts, options.ScannerWithDebug(&log.PrefixedLogger{Name: "aws"})) + scannerOpts = append(scannerOpts, options.ScannerWithDebug(prefixedLogger)) } if option.Trace { - scannerOpts = append(scannerOpts, options.ScannerWithTrace(&log.PrefixedLogger{Name: "aws"})) + scannerOpts = append(scannerOpts, options.ScannerWithTrace(prefixedLogger)) } if option.Region != "" {