More useful logs
This commit is contained in:
16
main.go
16
main.go
@@ -151,7 +151,7 @@ func processFile(filename string, pattern *regexp.Regexp, luaScript string) erro
|
|||||||
Error.Printf("Error reading file %s: %v", fullPath, err)
|
Error.Printf("Error reading file %s: %v", fullPath, err)
|
||||||
return fmt.Errorf("error reading file: %v", err)
|
return fmt.Errorf("error reading file: %v", err)
|
||||||
}
|
}
|
||||||
log.Printf("Successfully read file: %s", fullPath)
|
log.Printf("Successfully read file: %s, content length: %d bytes", fullPath, len(content))
|
||||||
|
|
||||||
fileContent := string(content)
|
fileContent := string(content)
|
||||||
result, err := process(fileContent, pattern, luaScript)
|
result, err := process(fileContent, pattern, luaScript)
|
||||||
@@ -159,14 +159,14 @@ func processFile(filename string, pattern *regexp.Regexp, luaScript string) erro
|
|||||||
Error.Printf("Error processing content of file %s: %v", fullPath, err)
|
Error.Printf("Error processing content of file %s: %v", fullPath, err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Printf("Successfully processed content of file: %s", fullPath)
|
log.Printf("Successfully processed content of file: %s, result length: %d bytes", fullPath, len(result))
|
||||||
|
|
||||||
err = os.WriteFile(fullPath, []byte(result), 0644)
|
err = os.WriteFile(fullPath, []byte(result), 0644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
Error.Printf("Error writing file %s: %v", fullPath, err)
|
Error.Printf("Error writing file %s: %v", fullPath, err)
|
||||||
return fmt.Errorf("error writing file: %v", err)
|
return fmt.Errorf("error writing file: %v", err)
|
||||||
}
|
}
|
||||||
log.Printf("Successfully wrote modified content to file: %s", fullPath)
|
log.Printf("Successfully wrote modified content to file: %s, new content length: %d bytes", fullPath, len(result))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -185,11 +185,12 @@ func process(data string, pattern *regexp.Regexp, luaScript string) (string, err
|
|||||||
log.Println("Lua math library loaded successfully.")
|
log.Println("Lua math library loaded successfully.")
|
||||||
|
|
||||||
// Load the Lua script
|
// Load the Lua script
|
||||||
|
log.Printf("Executing Lua script: %s", luaScript)
|
||||||
if err := L.DoString(luaScript); err != nil {
|
if err := L.DoString(luaScript); err != nil {
|
||||||
Error.Printf("Error in Lua script: %v", err)
|
Error.Printf("Error in Lua script: %v", err)
|
||||||
return data, fmt.Errorf("error in Lua script: %v", err)
|
return data, fmt.Errorf("error in Lua script: %v", err)
|
||||||
}
|
}
|
||||||
log.Println("Lua script executed successfully.")
|
log.Printf("Lua script executed successfully. Script: %s", luaScript)
|
||||||
|
|
||||||
// Process all regex matches
|
// Process all regex matches
|
||||||
result := pattern.ReplaceAllStringFunc(data, func(match string) string {
|
result := pattern.ReplaceAllStringFunc(data, func(match string) string {
|
||||||
@@ -206,10 +207,10 @@ func process(data string, pattern *regexp.Regexp, luaScript string) (string, err
|
|||||||
floatVal, err := strconv.ParseFloat(capture, 64)
|
floatVal, err := strconv.ParseFloat(capture, 64)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
L.SetGlobal(fmt.Sprintf("v%d", i+1), lua.LNumber(floatVal))
|
L.SetGlobal(fmt.Sprintf("v%d", i+1), lua.LNumber(floatVal))
|
||||||
log.Printf("Set v%d to %f", i+1, floatVal)
|
log.Printf("Set v%d to %f (capture: %s)", i+1, floatVal, capture)
|
||||||
} else {
|
} else {
|
||||||
L.SetGlobal(fmt.Sprintf("v%d", i+1), lua.LString(capture))
|
L.SetGlobal(fmt.Sprintf("v%d", i+1), lua.LString(capture))
|
||||||
log.Printf("Set v%d to %s", i+1, capture)
|
log.Printf("Set v%d to %s (capture: %s)", i+1, capture, capture)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -227,6 +228,7 @@ func process(data string, pattern *regexp.Regexp, luaScript string) (string, err
|
|||||||
// Get the value from the stack (if exists)
|
// Get the value from the stack (if exists)
|
||||||
if L.GetTop() >= i+1 {
|
if L.GetTop() >= i+1 {
|
||||||
returnValues[i] = L.Get(-12 + i)
|
returnValues[i] = L.Get(-12 + i)
|
||||||
|
log.Printf("Return value v%d: %v", i+1, returnValues[i])
|
||||||
} else {
|
} else {
|
||||||
returnValues[i] = lua.LNil
|
returnValues[i] = lua.LNil
|
||||||
}
|
}
|
||||||
@@ -256,7 +258,7 @@ func process(data string, pattern *regexp.Regexp, luaScript string) (string, err
|
|||||||
|
|
||||||
// If we have a value, replace it
|
// If we have a value, replace it
|
||||||
if newVal != "" {
|
if newVal != "" {
|
||||||
log.Printf("Replacing %s with %s", oldVal, newVal)
|
log.Printf("Replacing '%s' with '%s'", oldVal, newVal)
|
||||||
result = strings.Replace(result, oldVal, newVal, 1)
|
result = strings.Replace(result, oldVal, newVal, 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user