User Tools

Site Tools


writing_20log_20files

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

writing_20log_20files [2018/03/31 13:19]
127.0.0.1 external edit
writing_20log_20files [2018/04/17 19:29] (current)
tbest3112 Added syntax highlighting
Line 2: Line 2:
  
 //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:​\\ ​ //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:​\\ ​
 +<code bb4w>
         DEF PROClog(A$, F$) : LOCAL F%         DEF PROClog(A$, F$) : LOCAL F%
         F% = OPENUP(F$) : IF F% = 0 F% = OPENOUT(F$)         F% = OPENUP(F$) : IF F% = 0 F% = OPENOUT(F$)
Line 9: Line 10:
         CLOSE #F%         CLOSE #F%
         ENDPROC         ENDPROC
 +</​code>​
 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:​\\ ​ 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:​\\ ​
 +<code bb4w>
         PROClog(TIME$+":​ Application starting",​ @usr$+"​myprog.log"​)         PROClog(TIME$+":​ Application starting",​ @usr$+"​myprog.log"​)
 +</​code>​
 Here is an example of a log file created in this way:​\\ ​ 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:​27:​13:​ Application starting
writing_20log_20files.txt ยท Last modified: 2018/04/17 19:29 by tbest3112