` Procedure tracing template (Roberto Artigas Jr) - Icetips Article
Icetips - Templates, Tools & Utilities for Clarion Developers

Templates, Tools and Utilities
for Clarion Developers

Icetips Article

Back to article list   Search Articles     Add Comment     Printer friendly     Direct link  

Templates: Procedure tracing template
1998-12-31 -- Roberto Artigas Jr
 
Newsgroups: TopSpeed.Topic.Templates Editors note: Please note that some lines may wrap in the template code. Heaveno - Here is some template source for everyone. Add it to your favorite template chain. The original idea came from Craig (The Data Ferret) where he posted the source from a CW2003 Template to save the procedure name to a variable. I took the idea, expanded it a bit, and used it with ABC templates. This allows the conditional tracing to a log file of every procedure that you execute in your logic. The basic idea is to pass the name of the file, app, procedure, and trace line to a routine, prepend the current date and time, and write out to a log. You will have to furnish your own 'fnExecTraceProgram' routine. In my case this routine lies in a DLL. Since the logging routine opens and closes the log file, programs that are TERMINALLY ILL (GPF's with no clues) will have a trace of the routines that you have executed up to the routine that has died. At least it is better than nothing. You can conditionally remove the logging code and leave the variables. Just in case you need to pop up some message. Or you can remove both from generation. This is a very small template. Begining Template persons should be able deal with it. The only thing that I ask, that if you enhance, correct, modify, or otherwise improve it, please post it again. That way all will benefit. Here is the TEMPLATE..... #!==================================================================== #!==================================================================== #!==================================================================== #EXTENSION(WhoAmI_Proc, 'Save Procedure Name') #!==================================================================== #SHEET #TAB('WhoAmI_Proc') #PROMPT('Generate Trace Data',CHECK),%TraceData,DEFAULT(1),AT(10) #ENABLE(%TraceData=1) #PROMPT('Generate Trace Code',CHECK),%TraceCode,DEFAULT(1),AT(10) #ENDENABLE #ENDTAB #ENDSHEET #! %ProcedureTemplate = 'Source' #! %ProcedureTemplate = 'Window' #! %ProcedureTemplate = 'Frame' #! %ProcedureTemplate = 'Process' #! %ProcedureTemplate = 'Report' #! %ProcedureTemplate = 'Todo' #AT(%DataSection) #IF(%TraceData) LOC:NameFile STRING(12) LOC:NameAppl STRING(08) LOC:NameProc STRING(64) #ENDIF #ENDAT #! %ProcedureTemplate = 'Source' #AT(%ProcessedCode),FIRST #IF(%TraceData) LOC:NameFile = UPPER('%Application.Log') LOC:NameAppl = UPPER('%Application') LOC:NameProc = UPPER('%Procedure') #ENDIF #IF(%TraceCode) fnExecTraceProgram(LOC:NameFile,LOC:NameAppl,LOC:NameProc,'===Entry===') #ENDIF #ENDAT #! %ProcedureTemplate = 'Window' #! %ProcedureTemplate = 'Frame' #! %ProcedureTemplate = 'Process' #! %ProcedureTemplate = 'Report' #! %ProcedureTemplate = 'Todo' #AT(%ProcedureInitialize),FIRST #IF(%TraceData) LOC:NameFile = UPPER('%Application.Log') LOC:NameAppl = UPPER('%Application') LOC:NameProc = UPPER('%Procedure') #ENDIF #IF(%TraceCode) fnExecTraceProgram(LOC:NameFile,LOC:NameAppl,LOC:NameProc,'===Entry===') #ENDIF #ENDAT #!==================================================================== #! Here is a sample of the 'fnExecTraceProgram' routine. This will NOT compile since you are missing a variable and an API function call. It is only shown as an example so you can create your own routine. fnExecTraceProgram PROCEDURE (strFileName, strProgram, strRoutine, strLogLine) LIT:Separate EQUATE('|') LOC:strLine GROUP,PRE(LOC) strDate STRING(010) strSep0 STRING(001) strTime STRING(008) strSep1 STRING(001) strProg STRING(008) strSep2 STRING(001) strRout STRING(022) strSep3 STRING(001) strData STRING(080) END TraceFile FILE,DRIVER('ASCII'),PRE(Z0),NAME(LOC:FileName),CREATE Rec RECORD LogLine STRING(132) END END CODE LOC:FileName = CLIP(strFileName) IF ~fnFileExists(LOC:FileName) THEN ! <<< API >>> CREATE(TraceFile) CLOSE(TraceFile) END CLEAR(LOC:strLine) LOC:strDate = FORMAT(TODAY(),@D10) LOC:strSep0 = LIT:Separate LOC:strTime = FORMAT(CLOCK(),@T04) LOC:strSep1 = LIT:Separate LOC:strProg = strProgram LOC:strSep2 = LIT:Separate LOC:strRout = strRoutine LOC:strSep3 = LIT:Separate LOC:strData = CLIP(strLogLine) !STOP('FileName=''' & CLIP(LOC:FileName) & '''') OPEN(TraceFile) IF (ERROR()) THEN STOP('fnExecTraceProgram: ' & ERROR()) RETURN END CLEAR(Z0:Rec) Z0:LogLine = LOC:strLine APPEND(TraceFile,CLIP(Z0:LogLine)) CLOSE(TraceFile) RETURN Enjoy! Roberto Artigas Jr ascend@netten.net


Today is April 19, 2024, 9:57 am
This article has been viewed 35110 times.
Google search has resulted in 49 hits on this article since January 25, 2004.



Back to article list   Search Articles   Add Comment   Printer friendly

Login

User Name:

Password: