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 = "Form or View"<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 ("") <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("Master_Profile","Master")<br/>
If master_profile.IsNewNote Then<br/>
master_profile.form = "Master_Profile"<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( "" )<br/>
‘ Logs start of action
Call LogMyEvent ("Event", "Started in " & Production_Status & " mode ->><br/>
Name = " & agentname & " at " & Cstr(Now) , SEVERITY_LOW, Nothing) <br/>
Exit Sub<br/>
ErrorCheck:
If Err = 217 Then ‘FOR LEI<br/>
Set LEISession = New LCSession ("")<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 = "None") Then<br/>
Call LogMyEvent ("Metrics","Metrics - Ran in " & Production_Status &_<br/>
" mode ->> Name = " & agentname &" " & 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 <> "" 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("Error in " & Cstr(Getthreadinfo (LSI_THREAD_PROC))& _<br/>
"called from " & Cstr(Getthreadinfo (LSI_THREAD_CALLPROC)) &_<br/>
" << " & elogging &" >> " & 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 = "Production" And severity = SEVERITY_HIGH Then<br/>
master_profile.Production_Status = "Stage"<br/>
Call master_profile.save(True,True)<br/>
End If<br/>
LogMyErrorEx = LogErrorEx(msg, severity, doc)<br/>
If LEISession.Name <> "" 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("Error in " & Cstr(Getthreadinfo (LSI_THREAD_PROC))&_<br/>
"called from " & 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 = "None"<br/>
Else<br/>
tickdiff = "( Total Ticks = " & total_Ticks &" Total time ran >>" &_<br/>
Cstr(total_hours) & ":" & Cstr(total_min) & ":" & Cstr(total_sec ) & " )"<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/>