Sometimes, I need to gather debugging information from a Lotus Notes agent that multiple users may be using simultaneously. To do so, I assign each user session a random ID, which I can then employ as a sorting mechanism when I analyze the Lotus Notes agent log database. The following code will automate that for you.
' additional view in agentlog db
needs categorized 2nd column:
@Right( @Left( @If(A$LOGTYPE =
"Action"; A$ACTION; A$ERRMSG); "]" ); "[" )
' agent code:
Sub Initialize
'Handle all general errors
On Error Goto ErrorArea
Dim s As New NotesSession
Const AlwaysLog = True
Const LogCountOnly = False
Const NotesLogName = "multiuseragentlog.nsf"
Dim LogIt As Integer
Dim dbgLogIt As Integer
Dim dbgLogIt2 As Integer
Dim currentLog As NotesLog
Dim id As String
Dim LogID As Integer
Dim LogIDTxt As String
Dim NotesLogServer As String
Dim agent As NotesAgent
Dim startTime As NotesDateTime
Set startTime = New NotesDateTime( Cstr( Now ) )
Dim endTime As NotesDateTime
Dim timeDifference As Long
' ----------------------------- Enable Agent Logging
-----------------------------
LogIt% = True
dbgLogIt% = True
dbgLogIt2% = True
If AlwaysLog Then
Randomize
LogID = Round( Rnd()*10000, 0 )
LogIDTxt$ = Cstr(LogID)
id = "[" & LogIDTxt$ & "] "
REM NotesLogServer = ""
NotesLogServer = "serverName/NotesDomain"
Set agent = s.CurrentAgent
Set currentLog = New NotesLog
( agent.Name + " Agent in " +
s.CurrentDatabase.Title + " on "
+ s.CurrentDatabase.Server)
Call currentLog.OpenNotesLog
( NotesLogServer, NotesLogName )
Call currentLog.LogAction( id$ &
"------------------------------------------------
----------------------------------------------------")
Call currentLog.LogAction( id$ &
"The log is now {" & Format( startTime.LocalTime,
"mm/dd/yy hh:mm:ss") & "} turned on.")
End If
' ----------------------------- Enable Agent Logging
-----------------------------
'+ + + + + + + + + + + +
+ + + + + + + + + + + +
If AlwaysLog Then
Call currentLog.LogAction( id$ & "AlwaysLog is True" )
End If
If LogIt% Then
Call currentLog.LogAction( id$ & "LogIt% is True" )
End If
If dbgLogIt% Then
Call currentLog.LogAction( id$ & "dbgLogIt% is True" )
End If
If dbgLogIt2% Then
Call currentLog.LogAction( id$ & "dbgLogIt2% is True" )
End If
'+ + + + + + + + + + + +
+ + + + + + + + + + + +
' main program section
If AlwaysLog Then
Call currentLog.LogAction
( id$ & "Describe where you are in the program.")
End If
' main program section
'+ + + + + + + + + + +
+ + + + + + + + + + + + +
fin:
' ----------------------------- End Agent
Logging -----------------------------
Set endTime =
New NotesDateTime( Cstr( Now ) )
timeDifference& = endTime.
TimeDifference( startTime )
If AlwaysLog Then
Call currentLog.LogAction( id$ &
"The end of the program has been reached.
{" & Format( endTime.LocalTime, "Long Time") & "}")
Call currentLog.LogAction( id$ &
"Elapsed time: {" & Cstr( timeDifference& )
& "} seconds." )
Call currentLog.Close
End If
' ----------------------------- End Agent Logging
-----------------------------
Exit Sub
ErrorArea:
If AlwaysLog Then
REM Call currentLog.Logerror( id$ , Cstr( Err() )
& Error$ & " at " & Cstr( Erl() ) )
Call currentLog.Logerror(Err(), id$ & Error())
Call currentLog.LogAction( id$ & "The program
has abended. Man the lifeboats.
{" & Format(Now(), "Long Time") & "}")
Call currentLog.Close
End If
Exit Sub
End Sub
Do you have comments on this tip? Let us know.
Related information from SearchDomino.com:
This tip was submitted to the SearchDomino.com tip library by member Dennis Lowe. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.
This was first published in October 2006