Debugging to an external .txt file ?
Community Forums/General Help/Debugging to an external .txt file ?
| ||
Hello, I am currently coding some procedures to create a file, delete a file, save a file, load a file, close a file and i wonder what are the good practices in order to be able to debug possible problems/errors on the machines of users ? My current approach is to display a description of the checks, the results, the instructions, on the screen with Print(). Something like that : ;Check if the directory already exists ;if yes ;The directory already exists ;Check if the Map file already exists ;if yes ;The Map file already exists ;Ask the user if he wants to overwrite the existing Map file ;if yes ;Try to create the Map file ;Check if the Map file has been created ;if yes ;The Map file has been created ;Try to open the Map file ;Check if the Map file is open ;if yes ;The Map file is open ;Save the Map (Write the file) ;Close the file ;if no ;Error, the Map file is not open ;if no ;Error, the Map file has not been created ;if no ;Do not create the Map file ;if no ;The Map file does not exist ;Try to create the Map file ;Check if the Map file has been created ;if yes ;The Map file has been created ;Try to open the Map file ;Check if the Map file is open ;if yes ;The Map file is open ;Save the Map (Write the file) ;Close the file ;if no ;Error, the Map file is not open ;if no ;Error, the Map file has not been created ;if no ;Error, the directory does not exist However if for some reason the program crashes, the user may have difficulties to report precisely the error. So my idea is to write to an external .txt file the last ran procedure so that if a user has a problem he can simply send me this debug txt file and this will help me to have a better idea of what is the problem/error. Your thoughts ? How would you do that ? Thanks, |
| ||
Why restrict it to the local machine...you could send errors to a central server...with us er permission of course as program runs. |
| ||
Just use some kind of "logger" Maybe a bit easier than this, but maybe it helps to get the idea: https://github.com/GWRon/Dig/blob/master/base.util.logger.bmx in your app you could then add: OnEnd( EndHook ) Function EndHook() TLogFile.DumpLogs() End Function Which would output everything you logged as soon as the app "ends". If you want to log to file straight when the "print" happens (eg to get a log on segfaults/crashes) you will have to modify the "Log()" function to append the line to the file right in the function. bye Ron |
| ||
I wrote a little log_function that 'appends' every output I want to save to the extern file; instead of DebugLog I'm using my own LogPrint() function. Of course you need to fill up your source with your calls to LogPrint(ie: LogPrint "Entering Function X" - LogPrint "Exit Function X" to have something about the error. So if the program stops to function you have always the LAST entry (this is the reason you need to append to a file, otherwise if you open a stream and write to it... when the programs stop you lose everything), Of course this approach has a cost as you are writing on a stream/disk. I've moreover changed MaxIDE to write out to a (local) debuglog even the error catched (of course in debug)... next step is to dump all the debug info (objects, variables, etc) |
| ||
Thanks for your suggestions, i will do some tests. |
| ||
Here my code for Debug.txt Out debug.txt. |
| ||
My LogPrint function is like this |