[ |../../index.htm#lansa/l4wusr06_0025.htm]
現在地:
7.2 トレース・ハンドラー例
以下は内蔵トレース・ハンドラー・オブジェクトの例です。TracingOn.txt という名前のテキスト・ファイルの存在をチェックし、存在する場合は、実行時に自身をインストールしトレース・ファイルが作成されます。アプリケーションのコードに含まれるトレース・ステートメントは全て、このトレース・ファイルに出力されます。
このソースをコピーして、新しい RDMLX 再利用可能パーツに貼り付けてください。その後、、保存してコンパイルします。
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 (#Com_owner.FileExists( (*Sys_dir "TracingOn.txt") )) * Set this object as the system help handler #Sys_appln.TraceHandler <= #Com_owner Endif Endroutine Mthroutine Name(Initialize) Options(*redefine) Access(*private) #Com_owner.OpenTraceFile Endroutine Mthroutine Name(Terminate) Options(*redefine) Access(*private) #Com_owner.CloseTraceFile Endroutine Mthroutine Name(TraceMessage) Help('Executed whenever #sys_appln.TraceMessageData or #sys_appln.TraceMessageText is used') Options(*redefine) Access(*private) #Com_owner.WriteToFile( #ComponentName #Description #LineNumber #MessageText ) Endroutine Mthroutine Name(OpenTraceFile) Help('Create a new trace outputfile') Access(*private) Use Builtin(Stm_File_Open) With_Args(#Com_owner.GetNextFile Append N Y) To_Get(#FilHandle #io$sts) Endroutine Mthroutine Name(WriteToFile) Help('Write an entry in the trace output file') Access(*private) Define_Map For(*Input) Class(#prim_alph) Name(#ComponentName) Define_Map For(*Input) Class(#prim_alph) Name(#Description) Define_Map For(*Input) Class(#prim_nmbr) Name(#LineNumber) Define_Map For(*Input) Class(#prim_alph) Name(#MessageText) Define_Com Class(#prim_Dat) Name(#Now) #MessageText := #Now.now.AsLocalizedDateTime.AsString #Tab #ComponentName #Tab #LineNumber.asstring #Tab #MessageText Use Builtin(Stm_File_Write) With_Args(#FilHandle #MessageText) To_Get(#io$sts) Endroutine Mthroutine Name(CloseTraceFile) Access(*private) Use Builtin(Stm_File_Close) With_Args(#FilHandle) To_Get(#io$sts) Endroutine Mthroutine Name(TracingState) Options(*redefine) #MessageTracingActive := True Endroutine Mthroutine Name(GetNextFile) Access(*Private) Define_Map For(*Result) Class(#Prim_alph) Name(#Result) Define_Com Class(#prim_nmbr) Name(#Extension) Begin_Loop Using(#Extension) #Result := *Sys_dir "UserTrace" "." #Extension.asstring.rightAdjust( 3 "0" ) Leave If(*Not #Com_owner.FileExists( #Result )) End_Loop Endroutine Mthroutine Name(FileExists) Access(*private) Define_Map For(*input) Class(#prim_alph) Name(#Path) Define_Map For(*result) Class(#prim_boln) Name(#Result) Use Builtin(OV_FILE_SERVICE) With_Args(Check_File #Path) To_Get(#io$sts) #Result := (#io$sts = OK) Endroutine End_Com
[ |../../index.htm#lansa/l4wusr06_0025.htm]