diff --git a/pkg/cloud/aws/scanner/scanner.go b/pkg/cloud/aws/scanner/scanner.go index eac5f73d039d..9c0514691c7c 100644 --- a/pkg/cloud/aws/scanner/scanner.go +++ b/pkg/cloud/aws/scanner/scanner.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io/fs" - "strings" "golang.org/x/xerrors" @@ -44,11 +43,11 @@ func (s *AWSScanner) Scan(ctx context.Context, option flag.Options) (scan.Result } if option.Debug { - scannerOpts = append(scannerOpts, options.ScannerWithDebug(&defsecLogger{})) + scannerOpts = append(scannerOpts, options.ScannerWithDebug(&log.PrefixedLogger{Name: "aws"})) } if option.Trace { - scannerOpts = append(scannerOpts, options.ScannerWithTrace(&defsecLogger{})) + scannerOpts = append(scannerOpts, options.ScannerWithTrace(&log.PrefixedLogger{Name: "aws"})) } if option.Region != "" { @@ -160,13 +159,6 @@ func createState(freshState *state.State, awsCache *cache.Cache) (*state.State, return fullState, nil } -type defsecLogger struct { -} - -func (d *defsecLogger) Write(p []byte) (n int, err error) { - log.Logger.Debug("[defsec] " + strings.TrimSpace(string(p))) - return len(p), nil -} func addPolicyNamespaces(namespaces []string, scannerOpts []options.ScannerOption) []options.ScannerOption { if len(namespaces) > 0 { scannerOpts = append( diff --git a/pkg/commands/artifact/run.go b/pkg/commands/artifact/run.go index 5baa61787a57..53c64b5a7466 100644 --- a/pkg/commands/artifact/run.go +++ b/pkg/commands/artifact/run.go @@ -574,6 +574,7 @@ func initScannerConfig(opts flag.Options, cacheClient cache.Cache) (ScannerConfi disableEmbedded = true } configScannerOptions = misconf.ScannerOption{ + Debug: opts.Debug, Trace: opts.Trace, Namespaces: append(opts.PolicyNamespaces, defaultPolicyNamespaces...), PolicyPaths: append(opts.PolicyPaths, downloadedPolicyPaths...), diff --git a/pkg/log/logger.go b/pkg/log/logger.go index bc0f401cadab..b25e1395b5dd 100644 --- a/pkg/log/logger.go +++ b/pkg/log/logger.go @@ -3,6 +3,7 @@ package log import ( "os" "runtime" + "strings" xlog "github.com/masahiro331/go-xfs-filesystem/log" "go.uber.org/zap" @@ -121,3 +122,12 @@ func String(key, val string) zap.Field { } return zap.String(key, val) } + +type PrefixedLogger struct { + Name string +} + +func (d *PrefixedLogger) Write(p []byte) (n int, err error) { + Logger.Debugf("[%s] %s", d.Name, strings.TrimSpace(string(p))) + return len(p), nil +} diff --git a/pkg/misconf/scanner.go b/pkg/misconf/scanner.go index 39e6030e6d44..01bda19280c8 100644 --- a/pkg/misconf/scanner.go +++ b/pkg/misconf/scanner.go @@ -44,6 +44,7 @@ var enabledDefsecTypes = map[detection.FileType]types.ConfigType{ } type ScannerOption struct { + Debug bool Trace bool RegoOnly bool Namespaces []string @@ -257,6 +258,10 @@ func scannerOptions(t detection.FileType, opt ScannerOption) ([]options.ScannerO options.ScannerWithDataFilesystem(dataFS), ) + if opt.Debug { + opts = append(opts, options.ScannerWithDebug(&log.PrefixedLogger{Name: "misconf"})) + } + if opt.Trace { opts = append(opts, options.ScannerWithPerResultTracing(true)) }