Tighten up the logging a bit in loader

This commit is contained in:
2025-05-21 11:47:22 +02:00
parent 1afb311cdc
commit 5e3fb568ae

22
main.go
View File

@@ -152,37 +152,49 @@ func countTotalAchievements(achMap map[string][]NSQMessage) int {
// extractPlayerAchievementsFromFile is for Pass 1
func extractPlayerAchievementsFromFile(path string, wg *sync.WaitGroup) {
log := logger.Default.WithPrefix(filepath.Base(path))
log := logger.Default.WithPrefix(path)
log.Info("Extracting achievements")
defer wg.Done()
L := lua.NewState()
defer L.Close()
filestat, err := os.Stat(path)
if err != nil {
log.Error("error getting file stats: %v", err)
return
}
log.Info("File size: %.2f MB", float64(filestat.Size())/1024/1024)
log.Info("Running Lua file")
if err := L.DoFile(path); err != nil {
log.Error("error executing Lua file %q: %v", path, err)
return
}
log.Info("Getting Heimdall_Achievements")
heimdallAchievements := L.GetGlobal("Heimdall_Achievements")
if heimdallAchievements.Type() == lua.LTNil {
log.Warning("Heimdall_Achievements not found in %q. Skipping file.", path)
return
}
log.Info("Getting players table")
playersTableLua := L.GetField(heimdallAchievements, "players")
if playersTableLua.Type() == lua.LTNil {
log.Info("'players' table is nil in Heimdall_Achievements in %q. No player data to extract.", path)
return
}
log.Info("Casting players table")
playersTable, ok := playersTableLua.(*lua.LTable)
if !ok {
log.Warning("'players' field in Heimdall_Achievements is not a table in %q (type: %s). Skipping.", path, playersTableLua.Type().String())
return
}
var filePlayerAchievements []NSQMessage // Temporary list for this file's achievements
var filePlayerNames = make(map[string]bool) // Temporary set for this file's player names
var filePlayerAchievements []NSQMessage
var filePlayerNames = make(map[string]bool)
log.Info("Iterating over players")
counter := 0
playersTable.ForEach(func(playerNameLua lua.LValue, playerAchievementsLua lua.LValue) {
currentPlayerName := playerNameLua.String()
@@ -247,9 +259,9 @@ func extractPlayerAchievementsFromFile(path string, wg *sync.WaitGroup) {
allPlayerNamesGlobal[name] = true
}
globalDataMutex.Unlock()
log.Info("Extracted from %q. Players in file: %d. Achievements in file: %d.", path, len(filePlayerNames), len(filePlayerAchievements))
log.Info("Players in file: %d. Achievements in file: %d.", len(filePlayerNames), len(filePlayerAchievements))
} else {
log.Info("No player data or names extracted from %q.", path)
log.Info("No player data or names extracted")
}
}