I debug to a log like mad. A basic function for this is:
function WriteDebug(sText$ , iAppend)
fileID = OpenToWrite("debug.txt" , iAppend)
WriteLine(fileID , sText$)
CloseFile(fileID)
endfunction
Set sText$ to what string to log and set iAppend = 0 to overwrite the entire file or set it to 1 to add a new line to the file.
My normal version of this function also has timestamps which is often very helpful, but I'm writing this from my tablet so you're getting the abridged version.
I also often use this method to create a CSV file that I can open in OpenOfficeCalc. I typically set the first line of the file to be the column headers for the CSV spreadsheet.
I also use Notepad++ for viewing the logs because I can leave the log open and N++ just asks if I want to reload it when it has been updated.
This method also can enable you to see how far the program executed.