Using OpenLog for logging/ debugging XPages

It probably won’t make your admins happy if you constantly use print(“this”) in you Server-Side JavaScript code to print debug or error messages to the server’s console. Luckily there is a good alternative: use OpenNTF’s OpenLog project to log everything to a central database. The only problem is that the database doesn’t contain a library for Xpages (yet).

After some digging I found out that the TaskJam app from Elguji Software does have a SSJS library to be able to log messages from to the OpenLog database. To use it:

  • Download the OpenLog database and copy it to your server.
  • Download TaskJam.
  • Copy the OpenLogXPages script library from the TaskJam template to your XPage application.
  • Open your copy of the OpenLogXPages script library and update the variable “logDbPath” to reflect the path and location of your OpenLog database.
  • The OpenLogXPages script library contains code specifically for TaskJam that tries to retrieve the location of the log database from a view called vwControlPanel: disable that code.
  • On two places in the script library a variable called location is set to session.getURL(); if not specified. This is used in the log entries to show were the message came from. Since that property doesn’t always return the correct location, I”ve changed it to view.getPageName();
  • Add the OpenLogXpages script library to every page you want to debug/ log information. You can do this by adding a “resource” to basic/ resources property of your XPage or Custom Control (clientSide = false, location = /OpenLogXPages.jss). I’ve added the library to a Custom Control that is loaded on every XPage.

You’re now able to log events or error messages in your SSJS code by using:

log.logEvent( "Hello world" );
log.logError( e.toString(), null, e );

Since you’ve already downloaded TaskJam: don’t forget to have a look at it. It contains some good examples of how to use XPages.