Add trace log for skipped archive file when not enabled (#1961)

rh-pre-commit.version: 2.3.2
rh-pre-commit.check-secrets: ENABLED
This commit is contained in:
bplaxco authored and GitHub committed 2025-10-24 12:30:33 -05:00
1 parent c5ccbb9468
commit 3683f1700e
1 file changed
+14 -6
+14 -6
View File
@@ -12,6 +12,7 @@ import (
"github.com/h2non/filetype" "github.com/h2non/filetype"
"github.com/mholt/archives" "github.com/mholt/archives"
"github.com/rs/zerolog"
"github.com/zricethezav/gitleaks/v8/config" "github.com/zricethezav/gitleaks/v8/config"
"github.com/zricethezav/gitleaks/v8/logging" "github.com/zricethezav/gitleaks/v8/logging"
@@ -56,14 +57,21 @@ func (s *File) Fragments(ctx context.Context, yield FragmentsFunc) error {
// decide what to do with it. // decide what to do with it.
if err == nil && format != nil { if err == nil && format != nil {
if s.archiveDepth+1 > s.MaxArchiveDepth { if s.archiveDepth+1 > s.MaxArchiveDepth {
// Only warn when the feature is enabled var event *zerolog.Event
// Warn if the feature is enabled; else emit a trace log.
if s.MaxArchiveDepth != 0 { if s.MaxArchiveDepth != 0 {
logging.Warn().Str( event = logging.Warn()
"path", s.FullPath(), } else {
).Int( event = logging.Trace()
"max_archive_depth", s.MaxArchiveDepth,
).Msg("skipping archive: exceeds max archive depth")
} }
event.Str(
"path", s.FullPath(),
).Int(
"max_archive_depth", s.MaxArchiveDepth,
).Msg("skipping archive: exceeds max archive depth")
return nil return nil
} }
if extractor, ok := format.(archives.Extractor); ok { if extractor, ok := format.(archives.Extractor); ok {