Using OpenAudit to save my hair… :-)

At the moment I’m doing old school Notes development and needed to implement audit logging the in application. What better and easier to do than to head over to OpenNTF, grab the latest version of OpenAudit and implement it. Given I had some issues with some form aliases which I need to talk to Chad Schelfhout about it took me all of 90 minutes to implement. The component is now seamlessly embedded in the application – nice, quick and easy…

For me the the number one benefit of using open source is to be able to tweak the code to fit the exact problem domain. When creating applications I like to keep all databases for the application in a separate directory and hence group associated databases. When doing this it makes sense that the databases can automatically find the other databases of the application thus eliminating the need for additional configuration. This goes for Julians OpenLog application as well as OpenAudit. I previously implemented this for OpenLog and hence needed to do the same for Open Audit.

It proved very easy. A simple hack of the setAuditDb-method in the “Open Audit”-script library made it possible. Now when specifying “*/” at the start of the path name in the audit configuration (e.g. */OpenAudit.nsf) the method will assume that the database can be found in the same directory as the calling database.

My changes are in bold:

Public Sub setAuditDb(sServer As String, Byval sDatabase As String, sReplicaID As String)
   On Error Goto ErrorHandler
   If ( dbAudit Is Nothing ) Then
      If sServer = "*" Then
         sServer = System.ThisDatabase.Server
      End If
      If Left(sDatabase, 2) = "*/" Then
         'get database relative to current directory
         Dim session As New NotesSession
         Dim current_directory As String
         Dim sep As String
         If Left(session.Platform, 3) = "Win" Then
            sep = ||
         Else
            sep = |/|
         End If
         current_directory = Strleftback(System.ThisDatabase.FilePath, sep)
         sDatabase = current_directory + sep + Right(sDatabase, Len(sDatabase)-2)
      End If

      Set dbAudit = New NotesDatabase( sServer, sDatabase )
      If dbAudit.isopen Then

      Else
         Call dbAudit.OpenByReplicaID( sServer , sReplicaID )
         If dbAudit.isopen Then
         Else
            Set dbAudit = System.ThisDatabase
         End If
      End If
   End If

   Exit Sub

   'Catches any invalid Replica IDs, and will uses the current database then
   errorHandler:
   Set dbAudit = System.ThisDatabase
   Exit Sub
End Sub