• support code to set the logging levels for DEV< STAGE and PROD

    By David C Slatter 2 decades ago

    I added a profile document to my database that contains a “Production_Status” field with the options “Production, Stage, Development”



    And three fields Prod_Logging, Stg_Logging, Dev_Logging with the options

    “Actions, Agents, Buttons, Event, email, Forms, Metrics, Views, Other”.



    Production_Status will determine which Logging field is used.

    If the logging field contains the matching option from the “Call LogMyEvent ("Agents",” then the event will be logged.



    Call LogMyEvent ("Agents", "Agents - Documents Processed = " & Cstr(dc.Count)

    ,SEVERITY_LOW,Not



    Code Library Information

    Name: v_Master_Common

    Last Modification: 02/15/2007 10:18:17 AM

    LotusScript Code:

    Option Public

    Option Declare

    Uselsx "*lsxlc"

    Use "OpenLogFunctions"





    Public session As Notessession

    Public ws As Variant

    Public db As NotesDatabase

    Public agent As NotesAgent

    Public agentname As String

    Public error_status As Boolean

    Public master_profile As NotesDocument

    Public Production_Status As String

    Private IsActionStarted As Boolean

    Private Actioncount As Integer

    Private elogging As Variant

    Dim start_Ticks As Long

    Dim stop_Ticks As Long

    Public LEISession As Lcsession

    Public logtext As LCStream

    %INCLUDE "orgconst.lss"

    %INCLUDE "lsconst.lss"

    %INCLUDE "lserr.lss"





    Sub Initialize

    agentname = &quot;Form or View&quot;<br/>
    Set session = New NotesSession<br/>
    Set db = session.currentdatabase <br/>
    Set agent = session.CurrentAgent<br/>
    



    ‘ ADD FOR LEI

    If agent Is Nothing Then<br/>
        Set LEISession = New LCSession (&quot;&quot;)  <br/>
    Else<br/>
        Set LEISession = New LCSession (agent.Name) <br/>
        agentname =  agent.Name<br/>
    End If<br/>
    Set logtext = New LCStream<br/>
    

    ‘ END OF LEI



    ‘FOR Tracking the Time this runs

    start_Ticks = Getthreadinfo (LSI_THREAD_TICKS)<br/>
    



    'Get profile or create profile

    Set master_profile = db.GetProfileDocument(&quot;Master_Profile&quot;,&quot;Master&quot;)<br/>
    If  master_profile.IsNewNote Then<br/>
        master_profile.form = &quot;Master_Profile&quot;<br/>
        Call master_profile.Computewithform(False,False)<br/>
    End If<br/>
    


    'GET PRODUCTION_STATUS <br/>
    Production_Status = master_profile.Production_Status(0)<br/>
    elogging = Cvar( &quot;&quot; )<br/>
    



    ‘ Logs start of action

    Call LogMyEvent (&quot;Event&quot;, &quot;Started in &quot; &amp; Production_Status  &amp; &quot; mode   -&gt;&gt;<br/>
         Name = &quot; &amp; agentname &amp; &quot; at &quot; &amp; Cstr(Now)  ,  SEVERITY_LOW,  Nothing) <br/>
    Exit Sub<br/>
    

    ErrorCheck:

    If Err = 217 Then   ‘FOR LEI<br/>
        Set LEISession = New LCSession (&quot;&quot;)<br/>
        Resume Next<br/>
    End If<br/>
    Call LogMyErrorEx(Cstr(Getthreadinfo (LSI_THREAD_PROC)), SEVERITY_HIGH, Nothing)<br/>
    End<br/>
    

    End Sub



    Sub Terminate

    On Error Goto ErrorCheck<br/>
    Dim tick_msg As String<br/>
    tick_msg =  tickdiff(start_Ticks, Getthreadinfo (LSI_THREAD_TICKS))<br/>
    If Not ( tick_msg =  &quot;None&quot;)  Then<br/>
        Call LogMyEvent (&quot;Metrics&quot;,&quot;Metrics - Ran in &quot; &amp; Production_Status  &amp;_<br/>
                &quot; mode   -&gt;&gt; Name = &quot; &amp; agentname  &amp;&quot;   &quot; &amp; tick_msg,  _<br/>
                SEVERITY_LOW,  Nothing) <br/>
    End If<br/>
    Exit Sub<br/>
    

    ErrorCheck:

    Call LogMyErrorEx(Cstr(Getthreadinfo (LSI_THREAD_PROC)), SEVERITY_HIGH, Nothing)<br/>
    End<br/>
    

    End Sub

















    Function LogMyEvent (etype As String, msg As String, severity As String, _

                                 doc As NotesDocument) As String<br/>
    Dim uidoc As Variant<br/>
    On Error Goto ErrorCheck<br/>
    If Not Isempty(elogging)  Then <br/>
        If Not Isnull(Arraygetindex(  elogging, etype ) ) Then<br/>
            LogMyEvent  = LogEvent (msg, severity, doc)<br/>
            If  LEISession.Name &lt;&gt; &quot;&quot; Then  <br/>
                logtext.Text = msg<br/>
                Call LEISession.LogText(LCLOGSTREAMF_EVENT,logtext.text,0)<br/>
            End If<br/>
        End If<br/>
    End If<br/>
    Exit Function<br/>
    

    ErrorCheck:

    Call LogErrorEx(&quot;Error in &quot; &amp; Cstr(Getthreadinfo (LSI_THREAD_PROC))&amp; _<br/>
        &quot;called from &quot; &amp; Cstr(Getthreadinfo (LSI_THREAD_CALLPROC)) &amp;_<br/>
        &quot; &lt;&lt; &quot; &amp; elogging &amp;&quot; &gt;&gt; &quot; &amp; etype, SEVERITY_HIGH, Nothing)<br/>
    End<br/>
    

    End Function



    Function LogMyErrorEx( msg As String, severity As String, doc As NotesDocument)

                                                                As String<br/>
    Dim uidoc As Variant<br/>
    On Error Goto ErrorCheck<br/>
    


    'if error is received then set back to stage<br/>
    


    If Production_Status = &quot;Production&quot; And severity = SEVERITY_HIGH Then<br/>
        master_profile.Production_Status = &quot;Stage&quot;<br/>
        Call master_profile.save(True,True)<br/>
    End If<br/>
    


    LogMyErrorEx  = LogErrorEx(msg, severity, doc)<br/>
    If  LEISession.Name &lt;&gt; &quot;&quot; Then  <br/>
        logtext.Text = msg <br/>
        Call LEISession.LogText(LCLOGSTREAMF_EVENT,logtext.text,0)<br/>
        LEISession.status = LCFAIL_INVALID_CONNECTION<br/>
    End If<br/>
    Exit Function<br/>
    

    ErrorCheck:

    Call LogErrorEx(&quot;Error in &quot; &amp; Cstr(Getthreadinfo (LSI_THREAD_PROC))&amp;_<br/>
         &quot;called from &quot; &amp; Cstr(Getthreadinfo (LSI_THREAD_CALLPROC)), <br/>
         SEVERITY_HIGH, Nothing)<br/>
    End<br/>
    

    End Function



    Function tickdiff(starttick As Long, stoptick As Long) As String

    Dim total_Ticks As Long<br/>
    Dim total_hours As Long<br/>
    Dim total_min As Long<br/>
    Dim total_sec As Long <br/>
    On Error Goto ErrorCheck<br/>
    total_Ticks = stoptick - starttick<br/>
    total_Ticks = total_Ticks/ Getthreadinfo (LSI_THREAD_TICKS_PER_SEC)<br/>
    total_hours = (total_Ticks \ (60*60))<br/>
    total_min = (total_Ticks - (total_hours * 60*60)) \ 60<br/>
    total_sec = (total_Ticks - ( (total_hours * 60*60) + (total_min *60)))<br/>
    If total_Ticks = 0 Then<br/>
        tickdiff = &quot;None&quot;<br/>
    Else<br/>
        tickdiff =   &quot;( Total Ticks = &quot; &amp; total_Ticks &amp;&quot;  Total time ran &gt;&gt;&quot; &amp;_<br/>
              Cstr(total_hours) &amp; &quot;:&quot; &amp; Cstr(total_min)  &amp; &quot;:&quot; &amp; Cstr(total_sec ) &amp;  &quot; )&quot;<br/>
    End If<br/>
    Exit Function<br/>
    

    ErrorCheck:

    Call LogMyErrorEx(Cstr(Getthreadinfo (LSI_THREAD_PROC)), <br/>
                SEVERITY_HIGH, Nothing)<br/>
    End<br/>
    

    End Function


        <br/>