refactor: replace zap with slog (#6466)

Signed-off-by: knqyf263 <knqyf263@gmail.com>
Co-authored-by: Nikita Pivkin <nikita.pivkin@smartforce.io>
Co-authored-by: simar7 <1254783+simar7@users.noreply.github.com>
This commit is contained in:
Teppei Fukuda
2024-04-11 22:59:09 +04:00
committed by GitHub
parent 336c47ecc3
commit 94d6e8ced6
164 changed files with 1664 additions and 891 deletions

View File

@@ -360,7 +360,7 @@ func (r *runner) initCache(opts flag.Options) error {
if err != nil {
return xerrors.Errorf("unable to initialize the cache: %w", err)
}
log.Logger.Debugf("cache dir: %s", fsutils.CacheDir())
log.Debug("Cache dir", log.String("dir", fsutils.CacheDir()))
if opts.Reset {
defer cacheClient.Close()
@@ -400,12 +400,12 @@ func Run(ctx context.Context, opts flag.Options, targetKind TargetKind) (err err
defer func() {
if errors.Is(err, context.DeadlineExceeded) {
log.Logger.Warn("Increase --timeout value")
log.Warn("Increase --timeout value")
}
}()
if opts.GenerateDefaultConfig {
log.Logger.Info("Writing the default config to trivy-default.yaml...")
log.Info("Writing the default config to trivy-default.yaml...")
return viper.SafeWriteConfigAs("trivy-default.yaml")
}
@@ -484,7 +484,8 @@ func disabledAnalyzers(opts flag.Options) []analyzer.Type {
// Filter only enabled misconfiguration scanners
ma, err := filterMisconfigAnalyzers(opts.MisconfigScanners, analyzer.TypeConfigFiles)
if err != nil {
log.Logger.Errorf("Invalid misconfig scanners specified: %s defaulting to use all misconfig scanners", opts.MisconfigScanners)
log.Error("Invalid misconfiguration scanners specified, defaulting to use all misconfig scanners",
log.Any("scanners", opts.MisconfigScanners))
} else {
analyzers = append(analyzers, ma...)
}
@@ -528,7 +529,7 @@ func filterMisconfigAnalyzers(included, all []analyzer.Type) ([]analyzer.Type, e
return nil, xerrors.Errorf("invalid misconfiguration scanner specified %s valid scanners: %s", missing, all)
}
log.Logger.Debugf("Enabling misconfiguration scanners: %s", included)
log.Debug("Enabling misconfiguration scanners", log.Any("scanners", included))
return lo.Without(all, included...), nil
}
@@ -569,28 +570,28 @@ func initScannerConfig(opts flag.Options, cacheClient cache.Cache) (ScannerConfi
}
if len(opts.ImageConfigScanners) != 0 {
log.Logger.Infof("Container image config scanners: %q", opts.ImageConfigScanners)
log.Info("Container image config scanners", log.Any("scanners", opts.ImageConfigScanners))
}
if opts.Scanners.Enabled(types.VulnerabilityScanner) {
log.Logger.Info("Vulnerability scanning is enabled")
log.Logger.Debugf("Vulnerability type: %s", scanOptions.VulnType)
log.Info("Vulnerability scanning is enabled")
log.Debug("Vulnerability type", log.Any("type", scanOptions.VulnType))
}
// ScannerOption is filled only when config scanning is enabled.
var configScannerOptions misconf.ScannerOption
if opts.Scanners.Enabled(types.MisconfigScanner) || opts.ImageConfigScanners.Enabled(types.MisconfigScanner) {
log.Logger.Info("Misconfiguration scanning is enabled")
log.Info("Misconfiguration scanning is enabled")
var downloadedPolicyPaths []string
var disableEmbedded bool
downloadedPolicyPaths, err := operation.InitBuiltinPolicies(context.Background(), opts.CacheDir, opts.Quiet, opts.SkipPolicyUpdate, opts.MisconfOptions.PolicyBundleRepository, opts.RegistryOpts())
if err != nil {
if !opts.SkipPolicyUpdate {
log.Logger.Errorf("Falling back to embedded policies: %s", err)
log.Error("Falling back to embedded policies", log.Err(err))
}
} else {
log.Logger.Debug("Policies successfully loaded from disk")
log.Debug("Policies successfully loaded from disk")
disableEmbedded = true
}
configScannerOptions = misconf.ScannerOption{
@@ -617,18 +618,18 @@ func initScannerConfig(opts flag.Options, cacheClient cache.Cache) (ScannerConfi
// Do not load config file for secret scanning
if opts.Scanners.Enabled(types.SecretScanner) {
ver := canonicalVersion(opts.AppVersion)
log.Logger.Info("Secret scanning is enabled")
log.Logger.Info("If your scanning is slow, please try '--scanners vuln' to disable secret scanning")
log.Logger.Infof("Please see also https://aquasecurity.github.io/trivy/%s/docs/scanner/secret/#recommendation for faster secret detection", ver)
log.Info("Secret scanning is enabled")
log.Info("If your scanning is slow, please try '--scanners vuln' to disable secret scanning")
log.Infof("Please see also https://aquasecurity.github.io/trivy/%s/docs/scanner/secret/#recommendation for faster secret detection", ver)
} else {
opts.SecretConfigPath = ""
}
if opts.Scanners.Enabled(types.LicenseScanner) {
if opts.LicenseFull {
log.Logger.Info("Full license scanning is enabled")
log.Info("Full license scanning is enabled")
} else {
log.Logger.Info("License scanning is enabled")
log.Info("License scanning is enabled")
}
}