You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

TraceHandler Interface (PRIM_APP.ITraceHandler)
Trace Handler Interface for user defined tracing
Ancestors - None

Details


The iTraceHandler interface is a low overhead tracing mechanism that can be built in to applications to provide feedback for developer without the need to provide replacement runtime objects.
Tracing statements can be written in the RDMLX using the TraceMessageText and TraceMessageData methods and left in place. Unless a Trace Handler is implemented at runtime, they are effectively ignored.

Example


The sample below is a simple web tracehandler.
When this reusable part is created in the runtime and Trace=True added as a parameter on the querystring, tracing output is sent to the browser console.
Function Options(*DIRECT)
Begin_Com Role(*EXTENDS #PRIM_OBJT *implements #Prim_App.iTraceHandler)

  • Include a Define_Com for this reusable part in your web page
  • It will install itself as the TraceHandler if "trace=true" is included as a parameter on the URL
  • You can then embed #sys_appln.TraceMessageText( aaa bbb ccc ddd ) whereever you want to send trace data to the console.
  • Each parameter equates to a single trace statement
    Evtroutine Handling(#Com_Owner.CreateInstance)
    For Each(#Parameter) In(#sys_web.UrlParameters)
    Continue If(#Parameter.Name.UpperCase <> Trace)
    Continue If(#Parameter.Value.uppercase <> True)
    #Sys_appln.TraceHandler <= #Com_owner /* Set this to be the trace handler for the application */
    Leave
    Endfor
    Endroutine
    Mthroutine Name(TraceMessage) Help('Request to trace data received') Options(*redefine)
    #Com_owner.WriteToConsole( #ComponentName #Description #LineNumber #MessageText )
    Endroutine
    Mthroutine Name(WriteToConsole) Help('Write an entry to the browser console') 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(#Message)
    Define_Com Class(#prim_Dat) Name(#Now)
    #Message := #Now.now.AsLocalizedDateTime.AsString.Righttrim( "0" ) + " " + #ComponentName + " " + #Description + " " + #LineNumber.asstring + " " + #Message
    #sys_web.Console.Log( #Message )
    Endroutine
    Mthroutine Name(TracingState) Options(*redefine)
    #MessageTracingActive := True
    Endroutine
    End_Com

    Methods

    Name

    Description

    Initialize

    Executed when user tracing starts

    Terminate

    Executed when user tracing ends

    TraceMessage

    Executed whenever a trace message is issued ComponentName, Description, LineNumber, MessageText

    TracingState

    Is Tracing active? MessageTracingActive

    See also

    All Component Classes
    Technical Reference
  • No labels