Tip

Enhanced Lotus Notes agent logging

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

  • There are Comments. Add yours.

     
    TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

    REGISTER or login:

    Forgot Password?
    By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
    Sort by: OldestNewest

    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:

    Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.