diff --git a/cmd/format/format.go b/cmd/format/format.go index 9a4dffab..829c91a6 100644 --- a/cmd/format/format.go +++ b/cmd/format/format.go @@ -77,9 +77,6 @@ func Run(v *viper.Viper, statz *stats.Stats, cmd *cobra.Command, paths []string) }() } - // set a prefix on the default logger - log.SetPrefix("format") - var db *bolt.DB // open the db unless --no-cache was specified diff --git a/cmd/root_test.go b/cmd/root_test.go index 0b24c774..1ad40468 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -56,7 +56,7 @@ func TestOnUnmatched(t *testing.T) { checkOutput := func(level string, output []byte) { for _, p := range paths { - as.Contains(string(output), fmt.Sprintf("%s composite-formatter: no formatter for path: %s", level, p)) + as.Contains(string(output), fmt.Sprintf("%s no formatter for path: %s", level, p)) } } diff --git a/format/composite.go b/format/composite.go index 48e6746a..8b68a393 100644 --- a/format/composite.go +++ b/format/composite.go @@ -29,7 +29,6 @@ type CompositeFormatter struct { stats *stats.Stats globalExcludes []glob.Glob - log *log.Logger unmatchedLevel log.Level scheduler *scheduler @@ -40,7 +39,7 @@ type CompositeFormatter struct { func (c *CompositeFormatter) match(file *walk.File) []*Formatter { // first check if this file has been globally excluded if pathMatches(file.RelPath, c.globalExcludes) { - c.log.Debugf("path matched global excludes: %s", file.RelPath) + log.Debugf("path matched global excludes: %s", file.RelPath) return nil } @@ -72,7 +71,7 @@ func (c *CompositeFormatter) Apply(ctx context.Context, files []*walk.File) erro return fmt.Errorf("no formatter for path: %s", file.RelPath) } - c.log.Logf(c.unmatchedLevel, "no formatter for path: %s", file.RelPath) + log.Logf(c.unmatchedLevel, "no formatter for path: %s", file.RelPath) // no further processing to be done, append to the release list toRelease = append(toRelease, file) @@ -186,8 +185,6 @@ func NewCompositeFormatter( cfg: cfg, stats: statz, globalExcludes: globalExcludes, - - log: log.WithPrefix("composite-formatter"), unmatchedLevel: unmatchedLevel, scheduler: scheduler, diff --git a/format/formatter.go b/format/formatter.go index b4b4b11d..fcf1aaa3 100644 --- a/format/formatter.go +++ b/format/formatter.go @@ -162,9 +162,9 @@ func newFormatter( // initialise internal state if cfg.Priority > 0 { - f.log = log.WithPrefix(fmt.Sprintf("format | %s[%d]", name, cfg.Priority)) + f.log = log.WithPrefix(fmt.Sprintf("formatter | %s[%d]", name, cfg.Priority)) } else { - f.log = log.WithPrefix(fmt.Sprintf("format | %s", name)) + f.log = log.WithPrefix(fmt.Sprintf("formatter | %s", name)) } f.includes, err = compileGlobs(cfg.Includes) diff --git a/format/scheduler.go b/format/scheduler.go index 3dd1452e..c06e2817 100644 --- a/format/scheduler.go +++ b/format/scheduler.go @@ -49,7 +49,6 @@ func newBatchKey(formatters []*Formatter) batchKey { } type scheduler struct { - log *log.Logger batchSize int changeLevel log.Level formatters map[string]*Formatter @@ -179,7 +178,7 @@ func (s *scheduler) schedule(ctx context.Context, key batchKey, batch []*walk.Fi s.stats.Add(stats.Changed, 1) // log the change (useful for diagnosing issues) - s.log.Log( + log.Log( s.changeLevel, "file has changed", "path", file.RelPath, "prev_size", file.Info.Size(), @@ -247,7 +246,6 @@ func newScheduler( eg.SetLimit(runtime.NumCPU()) return &scheduler{ - log: log.WithPrefix("scheduler"), batchSize: batchSize, changeLevel: changeLevel, formatters: formatters, diff --git a/walk/cached.go b/walk/cached.go index c757ede2..3745d581 100644 --- a/walk/cached.go +++ b/walk/cached.go @@ -138,7 +138,7 @@ func NewCachedReader(db *bolt.DB, batchSize int, delegate Reader) (*CachedReader db: db, batchSize: batchSize, delegate: delegate, - log: log.WithPrefix("walk[cache]"), + log: log.WithPrefix("walk | cache"), eg: eg, updateCh: make(chan *File, batchSize*runtime.NumCPU()), } diff --git a/walk/filesystem.go b/walk/filesystem.go index 000aa9d8..7c22e605 100644 --- a/walk/filesystem.go +++ b/walk/filesystem.go @@ -128,7 +128,7 @@ func NewFilesystemReader( eg := errgroup.Group{} r := FilesystemReader{ - log: log.WithPrefix("walk[filesystem]"), + log: log.WithPrefix("walk | filesystem"), root: root, path: path, batchSize: batchSize, diff --git a/walk/git.go b/walk/git.go index 7681d150..fd079e68 100644 --- a/walk/git.go +++ b/walk/git.go @@ -119,6 +119,6 @@ func NewGitReader( path: path, stats: statz, eg: &errgroup.Group{}, - log: log.WithPrefix("walk[git]"), + log: log.WithPrefix("walk | git"), }, nil } diff --git a/walk/walk.go b/walk/walk.go index c405a481..c7ab6ff0 100644 --- a/walk/walk.go +++ b/walk/walk.go @@ -8,7 +8,6 @@ import ( "io/fs" "os" "path/filepath" - "time" "github.com/numtide/treefmt/stats" bolt "go.etcd.io/bbolt" @@ -75,7 +74,7 @@ func (f *File) Stat() (changed bool, info fs.FileInfo, err error) { // Some formatters mess with the mod time (e.g. dos2unix) but not to the same precision, // triggering false positives. // We truncate everything below a second. - if f.Info.ModTime().Truncate(time.Second) != current.ModTime().Truncate(time.Second) { + if f.Info.ModTime().Unix() != current.ModTime().Unix() { return true, current, nil }