I've attached my debug include file. You can use it outright, or take ideas from it. It writes to a debug.txt file in the media folder (writeable media folder in Appdata folder). You need to:
in your main code to kickstart the module. Wherever you want to output information to the log use:
DebugWrite("MyVariable = " + MyVariable$)
If your program is crashing, use
This ensures the text is saved to the file, otherwise it may not write it before the crash.
to save at regular intervals (slow, so don't use everywhere)
to write to the screen. This is for slow-moving output. If you write to it every cycle, it will just be a blur of unreadable information. If using the console, then before every sync(), call:
Quidquid latine dictum sit, altum sonatur