Refactor main function to replace print statements with structured logging for improved debugging

This commit is contained in:
MayaTheShy
2026-03-22 02:03:31 -04:00
parent 33cad06155
commit 50ec1ee6c2

View File

@@ -2847,7 +2847,7 @@ local function main()
else else
disabledRecipes[message.recipe] = true disabledRecipes[message.recipe] = true
end end
print("[NET] Recipe toggle: " .. message.recipe) log.info("NET", "Recipe toggle: %s", message.recipe)
saveDisabledRecipes() saveDisabledRecipes()
configDirty = true configDirty = true
bumpStateVersion() bumpStateVersion()
@@ -2855,7 +2855,7 @@ local function main()
pcall(broadcastState) pcall(broadcastState)
elseif message.type == "enable_all" then elseif message.type == "enable_all" then
disabledRecipes = {} disabledRecipes = {}
print("[NET] All recipes enabled") log.info("NET", "All recipes enabled")
saveDisabledRecipes() saveDisabledRecipes()
configDirty = true configDirty = true
bumpStateVersion() bumpStateVersion()
@@ -2865,21 +2865,21 @@ local function main()
for inputName in pairs(SMELTABLE) do for inputName in pairs(SMELTABLE) do
disabledRecipes[inputName] = true disabledRecipes[inputName] = true
end end
print("[NET] All recipes disabled") log.info("NET", "All recipes disabled")
saveDisabledRecipes() saveDisabledRecipes()
configDirty = true configDirty = true
bumpStateVersion() bumpStateVersion()
smelterNeedsRedraw = true smelterNeedsRedraw = true
pcall(broadcastState) pcall(broadcastState)
elseif message.type == "sort_barrel" and message.barrelName then elseif message.type == "sort_barrel" and message.barrelName then
print("[NET] Sort barrel: " .. message.barrelName) log.info("NET", "Sort barrel: %s", message.barrelName)
pcall(sortBarrel, message.barrelName) pcall(sortBarrel, message.barrelName)
pcall(broadcastState) pcall(broadcastState)
elseif message.type == "register_droppers" and message.clientId and message.droppers then elseif message.type == "register_droppers" and message.clientId and message.droppers then
-- Client is announcing its locally-attached droppers -- Client is announcing its locally-attached droppers
local cid = tostring(message.clientId) local cid = tostring(message.clientId)
clientDroppers[cid] = message.droppers clientDroppers[cid] = message.droppers
print(string.format("[NET] Client %s registered %d dropper(s)", cid, #message.droppers)) log.info("NET", "Client %s registered %d dropper(s)", cid, #message.droppers)
-- Rebuild the merged dropper list immediately -- Rebuild the merged dropper list immediately
local seenNames = {} local seenNames = {}
local merged = {} local merged = {}
@@ -2902,10 +2902,10 @@ local function main()
cache.droppers = merged cache.droppers = merged
pcall(broadcastState) pcall(broadcastState)
elseif message.type == "craft" and message.recipeIdx then elseif message.type == "craft" and message.recipeIdx then
print(string.format("[NET] Craft request: recipe #%d", message.recipeIdx)) log.info("NET", "Craft request: recipe #%d", message.recipeIdx)
local pok, ok, err = pcall(craftItem, message.recipeIdx) local pok, ok, err = pcall(craftItem, message.recipeIdx)
if not pok then if not pok then
print("[NET] craftItem crashed: " .. tostring(ok)) log.error("NET", "craftItem crashed: %s", tostring(ok))
err = tostring(ok) err = tostring(ok)
ok = false ok = false
end end
@@ -2922,7 +2922,7 @@ local function main()
end end
end) -- end pcall handler end) -- end pcall handler
if not handlerOk then if not handlerOk then
print("[NET] Handler error: " .. tostring(handlerErr)) log.error("NET", "Handler error: %s", tostring(handlerErr))
end end
end end
end end