Enhanced Lotus Notes agent logging

When multiple employees are using a Lotus Notes agent, it can be difficult to gather debugging information. This agent from SearchDomino.com member Dennis Lowe assigns each user session a random ID to simplify analysis of your Lotus Notes agent log database when errors occur.

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:

  • Tip: Find and manage all agents
  • Tip: Techniques for writing agents
  • Expert Advice: Debugging Web agents
  • Reference Center: Lotus Notes agent tip and resources

    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

    Dig deeper on Lotus Notes Domino Agents

    0 comments

    Oldest 

    Forgot Password?

    No problem! Submit your e-mail address below. We'll send you an email containing your password.

    Your password has been sent to:

    -ADS BY GOOGLE

    SearchWindowsServer

    Search400

    • iSeries tutorials

      Search400.com's tutorials provide in-depth information on the iSeries. Our iSeries tutorials address areas you need to know about...

    • V6R1 upgrade planning checklist

      When upgrading to V6R1, make sure your software will be supported, your programs will function and the correct PTFs have been ...

    • Connecting multiple iSeries systems through DDM

      Working with databases over multiple iSeries systems can be simple when remotely connecting logical partitions with distributed ...

    SearchEnterpriseLinux

    SearchDataCenter

    SearchExchange

    SearchContentManagement

    Close