Wednesday, December 07, 2005

Logging in TIBCO PortalBuilder 5.1

If you are like me, you believe that logging is a crucial part of application development. Good logging should be inserted during development, not added as an afterthought.

As I'm currently developing portlets, for eventual deployment into the TIBCO portal, I wanted to use Log4J within a JSR-168 portlet.

Initially, I tried to log information using the default portlet logger. That is:
getPortletContext().log("Interesting filth down here!");
This worked OK once I found out that the Portlet Role option must be checked in the Portal Builder Console for the Portal Item. To do this, go to the Portal tab, select the service link enclosing your portlet(s) (e.g. helloWorldPortletService), select Edit Service Configuration from the drop-down list and check Portlet Role in the Logging Settings page.

The big problem with log configuration under Log4J is configuring the log file name. I really dislike hard-coding file paths into the configuration files, particularly in this case where the portlet can be deployed by the TIBCO administrator into many different locations. I was looking for a way to generate a file path which would be in a "nice" location - for example, under the servlet context associated with the portlet, or in the portal log directory.

Log4J does allow access to the java system properties. So if the following property is set:
foo.bar
you can use the following in your log4j.properties to set the file:
log4j.appender.LOGFILE.file: ${foo.bar}/my.log
If I could get an appropriate system property set before the Log4J auto-configuration happens, then everything would be fine.

One potential method for setting the system property was to specify the directory on the JVM runtime (i.e. when the servlet engine starts), however I would prefer to avoid modifying the scripts installed with the product.

Investigation showed that the following interesting variable was present:
TIBCO_PS_HOME=C:\TIBCO\portal\5.1
which is pretty much what I needed.

Ideally, I would like to place the logs under the specific servlet instance logging directory, just as the portal does itself. If I could do it, this would mean that multiple instances of a servlet engine on the same host with the same portlet deployed to it would not share a log file. Alas, I have found no way to get this information (yet).

No comments: