Fix up logging a bit

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

21
main.go
View File

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