[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Enhancement: Timestamps in debug file



I'd like to add the capability of putting timestamps on the debug statements in HTTPAPI. I think there are a couple of times this would be helpful especially if the same file is used for debugging or especially long procedures.

It would appear to be two bit twiddle but I've come up with three alternative ways to add the capability and was looking for preferences/comments.

1. Add an additional parameter on HTTP_DEBUG(*ON:*OMIT:*ON)

2. Add a new procedure HTTP_DEBUG_TIMESTAMP(*ON)

3. Register a procedure that would do whatever someone wanted.

Discussion and comments:

1. HTTP_DEBUG is currently used to turn on or off debugging and to optionally name the file. Adding a third parameter (peUseTS) would be straight forward and follow the convention of modifying the debug file in the "open" statement. This would be implemented as a GLOBAL variable like the filename is currently. The default would be *OFF, but if passed, the variable would pick up the passed logical value. The actual implementation would be in http_dwrite just before the write to the file and would look like this pseudo code (since I haven't actually coded it yet):

If DEBUG_USE_TIMESTAMP;
   Eval   wwBuf = %char(%timestamp()) + ' '
   Eval   wwLen = %len(%trimr(wwBuf)) + 1 
   Callp  http_xlate(wwLen: wwBuf: TO_ASCII)
   Callp  write(wkDbg: %addr(wwBuf): wwLen)  // takes advantage of the fact that the debug file is a stream file and will add data without CRLF
EndIf 

2. This option is basically the same as #1 except the parameter that changes the GLOBAL variable is changed using a separate procedure. This would be similar to the way the additional headers are added to the http headers. Rather than glum up the HTTP_DEBUG(*ON) with more parameters, we just make a new procedure to modify the GLOBAL variable.

3. This option is to make a new exit point in the http_dwrite procedure similar to the way exit procedures are added to other routines. The user written procedure would be called immediately before the data that is being written. You could put anything you wanted into the debug file. This could be used to make alternate forms of the timestamp like say the time only or using a global variable it could prefix each line with some token for what part of the program was being run. I am not entirely clear on the coding for this one. This would require the use of http_xproc() to set the exit procedure. In http_dwrite we would add something like this:
        
*********************************************************                  
 * Call user supplied procedure                           
 *********************************************************                  
c                   if        wkAddDebugProc <> *NULL                       
c                   callp     Debug_Data( data: datalen )
c                   Callp     write(wkDbg: %addr(data): dataLen)    
c                   endif

In the user program, they would code a procedure:

*++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
 * my_procedure():  Called by HTTPAPI to add data before        
 *                  each line of debug output                                    
 *++++++++++++++++++++++++++++++++++++++++++++++++++++++++  
P my_procedure    B                                         
D my_procedure    PI
D   reallyBigData             32766a
D   reallyBigDataLen             10i 0

D* lineCounter    S              10i 0 STATIC

C                   eval      reallyBigData    = %char(%time()) + ' '
C*                  eval      lineCounter += 1 
C*                  eval      reallyBigData    = %char(lineCounter)
C                   eval      reallyBigDataLen = %len(%trimr(reallyBigData)) + 1
C                   callp     http_xlate(reallyBigDataLen:  
C                                        reallyBigData:
C                                        TO_ASCII )
P my_procedure    E

This third option would involve the most delay in the process? but would be the most flexible. In the above example, I think the commented out code would print a line number on each line so you could say "on line 10 you forgot the s". Or if you had a long process, you might have a global variable and "print" where you are in the program (whereAmI = 'First'/'Second'/'Sending'/'Receiving 2'/'Whatever'). 

Maybe there could be a combo option that would use the "default" timestamp mode OR the user written procedure?

What say ye? Worthwhile idea? A different implementation? Preferences?

Mike Krebs
-----------------------------------------------------------------------
This is the FTPAPI mailing list.  To unsubscribe, please go to:
http://www.scottklement.com/mailman/listinfo/ftpapi
-----------------------------------------------------------------------