From 385fbc36cf7dd5e446dbfd79b501fb0800423aa4 Mon Sep 17 00:00:00 2001 From: Brian McGee Date: Tue, 14 May 2024 21:03:56 +0100 Subject: [PATCH] feat: improve formatter cache debug logging Signed-off-by: Brian McGee --- cache/cache.go | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/cache/cache.go b/cache/cache.go index 2a35458a..dd0818e7 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -89,14 +89,23 @@ func Open(treeRoot string, clean bool, formatters map[string]*format.Formatter) return fmt.Errorf("failed to retrieve cache entry for formatter %v: %w", name, err) } - clean = clean || entry == nil || !(entry.Size == stat.Size() && entry.Modified == stat.ModTime()) - logger.Debug( - "checking if formatter has changed", - "name", name, - "clean", clean, - "entry", entry, - "stat", stat, - ) + isNew := entry == nil + hasChanged := entry != nil && !(entry.Size == stat.Size() && entry.Modified == stat.ModTime()) + + if isNew { + logger.Debugf("formatter '%s' is new", name) + } else if hasChanged { + logger.Debug("formatter '%s' has changed", + name, + "size", stat.Size(), + "modTime", stat.ModTime(), + "cachedSize", entry.Size, + "cachedModTime", entry.Modified, + ) + } + + // update overall clean flag + clean = clean || isNew || hasChanged // record formatters info entry = &Entry{