Fix up the logs a little
This commit is contained in:
26
main.go
26
main.go
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"modify/processor"
|
||||
"modify/utils"
|
||||
@@ -66,6 +67,7 @@ func main() {
|
||||
|
||||
// Then aggregate all the globs and deduplicate them
|
||||
globs := utils.AggregateGlobs(commands)
|
||||
logger.Debug("Aggregated %d globs before deduplication", utils.CountGlobsBeforeDedup(commands))
|
||||
|
||||
// Resolve all the files for all the globs
|
||||
logger.Info("Found %d unique file patterns", len(globs))
|
||||
@@ -90,6 +92,13 @@ func main() {
|
||||
// Then for each file run all commands associated with the file
|
||||
workers := make(chan struct{}, *utils.ParallelFiles)
|
||||
wg := sync.WaitGroup{}
|
||||
|
||||
// Add performance tracking
|
||||
startTime := time.Now()
|
||||
fileCount := 0
|
||||
modCount := 0
|
||||
var fileMutex sync.Mutex
|
||||
|
||||
for file, commands := range associations {
|
||||
workers <- struct{}{}
|
||||
wg.Add(1)
|
||||
@@ -97,6 +106,9 @@ func main() {
|
||||
defer func() { <-workers }()
|
||||
defer wg.Done()
|
||||
|
||||
// Track per-file processing time
|
||||
fileStartTime := time.Now()
|
||||
|
||||
fileData, err := os.ReadFile(file)
|
||||
if err != nil {
|
||||
logger.Error("Failed to read file %q: %v", file, err)
|
||||
@@ -124,6 +136,12 @@ func main() {
|
||||
|
||||
// Sort commands in reverse order for safe replacements
|
||||
fileDataStr, count := utils.ExecuteModifications(modifications, fileDataStr)
|
||||
|
||||
fileMutex.Lock()
|
||||
fileCount++
|
||||
modCount += count
|
||||
fileMutex.Unlock()
|
||||
|
||||
logger.Info("Executed %d modifications for file %q", count, file)
|
||||
|
||||
err = os.WriteFile(file, []byte(fileDataStr), 0644)
|
||||
@@ -131,10 +149,18 @@ func main() {
|
||||
logger.Error("Failed to write file %q: %v", file, err)
|
||||
return
|
||||
}
|
||||
|
||||
logger.Debug("File %q processed in %v", file, time.Since(fileStartTime))
|
||||
}, file, commands)
|
||||
}
|
||||
wg.Wait()
|
||||
|
||||
processingTime := time.Since(startTime)
|
||||
logger.Info("Processing completed in %v", processingTime)
|
||||
if fileCount > 0 {
|
||||
logger.Info("Average time per file: %v", processingTime/time.Duration(fileCount))
|
||||
}
|
||||
|
||||
// TODO: Also give each command its own logger, maybe prefix it with something... Maybe give commands a name?
|
||||
// Do that with logger.WithField("loglevel", level.String())
|
||||
// Since each command also has its own log level
|
||||
|
||||
Reference in New Issue
Block a user