Skip to content

Commit

Permalink
feat: log changed files at error level when --fail-on-change is enabled
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
brianmcgee committed Aug 13, 2024
1 parent 31e363d commit c53a1f1
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions cli/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c53a1f1

Please sign in to comment.