Fix up logging a bit

This commit is contained in:
2025-03-12 21:46:12 +01:00
parent a246b79240
commit 2b2f5d3812

23
main.go
View File

@@ -35,6 +35,7 @@ type ExtData struct {
}
var debug bool
func main() {
raw := flag.Bool("r", false, "More application friendly output")
debugF := flag.Bool("d", false, "Debug mode")
@@ -48,14 +49,10 @@ func main() {
if debug {
log.Printf("Scanning directory: %s", dir)
}
//log.Printf("%#v", IsStringBinary("using RimWorld;"))
//return
files := make(chan string, 10000)
//status := make(chan error)
//go GetSyncFilesRecursively(dir, files, status)
files <- "CompRegisterAlternateGraphic.cs"
status := make(chan error)
go GetSyncFilesRecursively(dir, files, status)
extensionTypeCount := sync.Map{}
wg := sync.WaitGroup{}
@@ -63,6 +60,9 @@ func main() {
wg.Add(1)
go func(file string) {
defer wg.Done()
if debug {
log.Printf("Processing file: %s", file) // Log the file being processed
}
f, err := os.Open(file)
if err != nil {
if debug {
@@ -70,6 +70,7 @@ func main() {
}
return
}
defer f.Close() // Ensure the file is closed after processing
scanner := bufio.NewScanner(f)
if scanner.Scan() {
@@ -78,12 +79,12 @@ func main() {
if IsStringBinary(scanner.Text()) {
extData.(*ExtData).binaryCount++
if debug {
log.Printf("Binary file: %s (%s)", file, ext)
log.Printf("Binary file detected: %s (%s)", file, ext) // Log binary file detection
}
} else {
extData.(*ExtData).textCount++
if debug {
log.Printf("Text file: %s (%s)", file, ext)
log.Printf("Text file detected: %s (%s)", file, ext) // Log text file detection
}
}
} else if err := scanner.Err(); err != nil {
@@ -91,8 +92,6 @@ func main() {
log.Printf("Error reading line from file %s: %v", file, err)
}
}
f.Close()
}(file)
}
wg.Wait()
@@ -106,7 +105,9 @@ func main() {
if *raw {
fmt.Println(extData.ext)
} else {
log.Printf("Extension: %q, Binary Count: %d, Text Count: %d", extData.ext, extData.binaryCount, extData.textCount)
if debug {
log.Printf("Extension: %q, Binary Count: %d, Text Count: %d", extData.ext, extData.binaryCount, extData.textCount)
}
}
}
return true