Changeset 1728


Ignore:
Timestamp:
Feb 17, 2014, 11:10:18 PM (12 years ago)
Author:
John Small
Message:

Ticket 512: Improvements to logfm2.cmd

Enhanced error-handling

No log file parameter defaults to fm2.log
Checks for write-ability of the log file and prompts for action if unwritable

Other improvements

All logs are written to the <fm2dir>\debug\logfiles directory

(so they are easy to find and do not clutter other directories)

Headers and footers are written to the log file to aid in interpreting

the contents

When FM/2 closes the log file is opened

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/logfm2.cmd

    r1599 r1728  
    55 *
    66 * Change log:
    7  *    11 Jul 17 JBS Corrected redirection syntax
     7 *    17 Jul 11 JBS Corrected redirection syntax
     8 *    17 Feb 14 JBS Ticket 512: Improvements
     9 *        Enhanced error-handling
     10 *           No log file parameter defaults to fm2.log
     11 *           Checks for write-ability of the log file and prompts for action if unwritable
     12 *        Other improvements
     13 *           All logs are written to the <fm2dir>\debug\logfiles directory
     14 *             (so they are easy to find and do not clutter other directories)
     15 *           Headers and footers are written to the log file to aid in interpreting
     16 *             the contents
     17 *           When FM/2 closes the log file is opened
    818 *
    919 */
    10        
     20
     21/* Determine and ensure existence of log file directory */
     22parse source . . thispgm
     23logfiledir = filespec('D', thispgm) || filespec('P', thispgm) || 'LogFiles'
     24call SysMkDir logfiledir
     25
     26/* Process parameter, using default if none is passed. */
    1127parse arg logfile
    12 fulllogfilename = stream(logfile, 'c', 'query exists')
    13 if fulllogfilename = '' then
    14    fulllogfilename = logfile
    15 call lineout fulllogfilename, date() time() 'Logging started...'
    16 call directory '..'
    17 'start fm3.exe 1>>'fulllogfilename '2>&1'
     28logfile = strip(logfile)
     29if logfile = '' then
     30  logfile = 'fm2.log'         /* Default to "fm2.log" */
     31
     32/* Check "write-ablility" and set the full filename for the log file */
     33do until logfile_ok = 1
     34   fulllogfilename = logfiledir || '\' || filespec('N', logfile)
     35   logfile_exists = (stream(fulllogfilename, 'c', 'query exists') \= '')
     36   /* Check for locked file here */
     37   if stream(fulllogfilename, 'c', 'open write') = 'READY:' then
     38      logfile_ok = 1
     39   else
     40      do
     41         logfile_ok = 0
     42         rc = stream(fulllogfilename, 'c', 'close')
     43         say 'Unable to open existing log file:' logfile
     44         say
     45         say logfile 'may be locked by another process.'
     46         say
     47         say 'Please close any processes that may be using' logfile || '.'
     48         say '(Another instance of a logged FM/2 or an editor perhaps?)'
     49         say
     50         say 'Just press the Enter key to retry' logfile || '.'
     51         say 'Or type in a new log file name:'
     52         newlogfile = strip(linein())
     53         if newlogfile \= '' then
     54            logfile = newlogfile
     55      end
     56end
     57
     58/* Write "header" */
     59if logfile_exists = 1 then
     60   do
     61      call lineout fulllogfilename, LinePrefix() 'Created log file:' fulllogfilename
     62      /* Write "instructions" to file here? */
     63   end
     64call lineout fulllogfilename, LinePrefix() 'Logging started.'
     65call stream fulllogfilename, 'c', 'close'
     66
     67/* Start FM/2 */
     68call directory logfiledir || '\..\..'
     69'fm3.exe # 2>>' || fulllogfilename
     70
     71/* Write "footer" */
     72call lineout fulllogfilename,  LinePrefix() 'Logging ended.'
     73call stream fulllogfilename, 'c', 'close'
     74
     75/* Open log file for viewing */
     76call SysSetObjectData fulllogfilename, 'OPEN=DEFAULT'
    1877return
     78
     79LinePrefix: procedure
     80return '###' date() time()
     81
Note: See TracChangeset for help on using the changeset viewer.