Log errors to text files, screenshots, and remote servers.

1 vote · 0 comments

There may come a time when you want to log Lua errors in MOAI and report them. This script will:

  • intercept the error and trace
  • save the error and a screenshot of the game at the time
  • upload those files to a remote FTP server

All these items together should help you debug your application easier with no effort on your testers.

If you have a sign-in system set up in your game you could even dump that info too so you know who reported that error automatically.

Note: for me MOAISim.setTraceback() doesn't register in the ZeroBraneStudio IDE. Outside of ZeroBrane Studio it works fine.

raw ·
copy
· download
ftp = require("socket.ftp") ltn12 = require("ltn12") function handleError(trace) print("ERROR!") local filename = "error" .. os.date("-%m_%d_%Y-%H.%M.%S", os.time()) print("- writing error to file") local file = io.open("logs/" .. filename .. ".txt", "w") file:write(trace) file:close() print("- uploading error text to server") ftp.put{ host = "ftp.yoursite.com", user = "yourFtpUser", password = "password", command = "STOR", type = "a", argument = filename .. ".txt", source = ltn12.source.file(io.open("logs/" .. filename .. ".txt", "r")) } print("- capturing screenshot of error") img = MOAIImage.new() --fbf = MOAIGfxDevice.getFrameBuffer() -- Works, but procudes weird "Attempt to access MOAILuaObject userdata tagged for garbage collection" errors... fbf = MOAIFrameBufferTexture.new () fbf:setRenderTable({game.layer, game.GUIlayer}) fbf:init (game.screenWidth, game.screenHeight) MOAIRenderMgr.setBufferTable ({fbf}) fbf:grabNextFrame(img, function() print("- writing screenshot to file") img:writePNG("logs/" .. filename .. ".png") print("- uploading error screenshot to server") ftp.put{ host = "ftp.yoursite.com", user = "yourFtpUser", password = "password", command = "STOR", type = "i", argument = filename .. ".png", source = ltn12.source.file(io.open("logs/" .. filename .. ".png", "rb")) } -- show on console print("- here's the error the broke the game:") print(trace) end) end MOAISim.setTraceback(handleError)

Be the first to comment

Sign in with OpenID