by Richard Russell, June 2010
Conventionally, a log file is a plain-text file containing a list of records (probably timed) corresponding to significant events. For example, a program might log the occurrence of errors for subsequent analysis.
To maximise the chance of a valid log file being created, even if the program writing it crashes, it is safer to close the file after every record is written. This reduces the time for which data is held in volatile RAM buffers, and the reliance on memory contents.
The code below is one example of how this can be achieved:
DEF PROClog(A$, F$) : LOCAL F% F% = OPENUP(F$) : IF F% = 0 F% = OPENOUT(F$) IF F% = 0 ERROR 100, "Cannot create log file "+F$ PTR#F% = EXT#F% PRINT #F%,A$ : BPUT#F%,10 CLOSE #F% ENDPROC
Each time you want to log an event call this procedure with the first parameter being the string to write, and the second parameter being the path/name of the log file. For example:
PROClog(TIME$+": Application starting", @usr$+"myprog.log")
Here is an example of a log file created in this way:
Mon.07 Jan 2008,09:27:13: Application starting Mon.07 Jan 2008,09:28:09: Cannot open file C:\home\rtr\vp\lenscal\initial_16x9.zfc Mon.07 Jan 2008,09:28:27: Cannot solve equations (singular matrix) Mon.07 Jan 2008,09:28:31: Application quitting