From c53a1f1b776107ded11ea4e6df6000dc725b6c8c Mon Sep 17 00:00:00 2001 From: Brian McGee Date: Tue, 13 Aug 2024 20:37:16 +0100 Subject: [PATCH] feat: log changed files at error level when --fail-on-change is enabled By default, we log the changed file at debug level. If the `--fail-on-change` flag has been provided, we log the changed file at error level. This is to surface issues better in CI pipelines for example. Signed-off-by: Brian McGee --- cli/format.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cli/format.go b/cli/format.go index dc1d6732..4b8f7fa1 100644 --- a/cli/format.go +++ b/cli/format.go @@ -427,13 +427,20 @@ func (f *Format) detectFormatted(ctx context.Context) func() error { if changed { // record the change stats.Add(stats.Formatted, 1) - // log the change for diagnostics - log.Debug( + + logMethod := log.Debug + if f.FailOnChange { + // surface the changed file more obviously + logMethod = log.Error + } + + // log the change + logMethod( "file has changed", - "path", file.Path, + "path", file.RelPath, "prev_size", file.Info.Size(), - "current_size", newInfo.Size(), "prev_mod_time", file.Info.ModTime().Truncate(time.Second), + "current_size", newInfo.Size(), "current_mod_time", newInfo.ModTime().Truncate(time.Second), ) // update the file info