Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_OBJT *implements #prim_app.iTraceHandler)
Define Field(#FilHandle) Type(*dec) Length(3) Decimals(0)
Define_Com Class(#prim_alph) Name(#Tab)
Evtroutine Handling(#Com_Owner.CreateInstance)
#Tab := (09).asChar
#Com_owner.InstallTracing
Endroutine
Mthroutine Name(InstallTracing) Help('Plug in the trace handler to the Application') Access(*private) * This example uses a text file as the trigger to implement user tracing. * Alternately you might consider using a registry entry If
* Alternately you might consider using a registry entry
If (#Com_owner.FileExists( (*Sys_dir "TracingOn.txt") )) * Set this object as the system help handler
* Set this object as the system help handler
#Sys_appln.TraceHandler <= #ComTraceHandler <= #Com_owner
Endif
Endroutine
Mthroutine Mthroutine NameName(Initialize) Options Options(*redefine) Access Access(*private)
#Com_owner.OpenTraceFile
Endroutine Mthroutine Name
Mthroutine Name(Terminate) Options Options(*redefine) Access Access(*private)
#Com_owner.CloseTraceFile
Endroutine
Mthroutine Mthroutine NameName(TraceMessage) Help Help('Executed whenever #sysExecuted whenever #sys_appln.TraceMessageData or #sysTraceMessageData or #sys_appln.TraceMessageText is usedTraceMessageText is used') Options Options(*redefine) Access Access(*private)
#Com_owner.WriteToFile( #ComponentName #Description #LineNumber #MessageText #ComponentName #Description #LineNumber #MessageText ) Endroutine Mthroutine Mthroutine NameName(OpenTraceFile) Help Help('Create a new trace outputfileCreate a new trace outputfile') Access Access(*private)
Use Use BuiltinBuiltin(Stm_File_Open) With With_Args(#Com_owner.GetNextFile Append N Y) ToGetNextFile Append N Y) To_Get(#FilHandle #io$sts#FilHandle #io$sts)
Endroutine Mthroutine Name
Mthroutine Name(WriteToFile) Help Help('Write an entry in the trace output fileWrite an entry in the trace output file') Access Access(*private)
Define_Map ForMap For(*Input) Class Class(#prim_alph) Name Name(#ComponentName)
Define_Map ForMap For(*Input) Class Class(#prim_alph) Name Name(#Description)
Define_Map ForMap For(*Input) Class Class(#prim_nmbr) Name Name(#LineNumber)
Define_Map ForMap For(*Input) Class Class(#prim_alph) Name Name(#MessageText)
Define_Com ClassCom Class(#prim_Dat) Name Name(#Now) #MessageText
#MessageText := #Now Now.now.AsLocalizedDateTime.AsString #Tab #ComponentName #Tab #LineNumber.asstring #Tab #MessageText Use Builtin
Use Builtin(Stm_File_Write) With With_Args(#FilHandle #MessageText) To#FilHandle #MessageText) To_Get(#io$sts)
Endroutine
Mthroutine Mthroutine NameName(CloseTraceFile) Access Access(*private) Use Builtin
Use Builtin(Stm_File_Close) With With_Args(#FilHandle) To To_Get(#io$sts)
Endroutine
Mthroutine Mthroutine NameName(TracingState) Options Options(*redefine)
#MessageTracingActive #MessageTracingActive := True True
Endroutine
Mthroutine Mthroutine NameName(GetNextFile) Access Access(*Private)
Define_Map ForMap For(*Result) Class Class(#Prim_alph) Name Name(#Result)
Define_Com ClassCom Class(#prim_nmbr) Name Name(#Extension)
Begin_Loop UsingLoop Using(#Extension) #Result
#Result := *Sys_dir "UserTrace" "." #Extension.asstring.rightAdjust( 3 3 "0" )
Leave Leave IfIf(*Not #ComNot #Com_owner.FileExists( #Result #Result ))
End_Loop
Endroutine Mthroutine Name
Mthroutine Name(FileExists) Access Access(*private)
Define_Map ForMap For(*input) Class Class(#prim_alph) Name Name(#Path)
Define_Map ForMap For(*result) Class Class(#prim_boln) Name Name(#Result)
Use Use BuiltinBuiltin(OV_FILE_SERVICE) With With_Args(Check_File #Path) ToFile #Path) To_Get(#io$sts)
#Result #Result := (#io$sts #io$sts = OK OK)
Endroutine
End_Com |