Tuesday, November 16, 2010

Java applet logging

The chances are that you are already using Apache commons logging and log4j in your application. A new challenge is how you do logging for Applet. By that I mean, dumping the output to applet Java console.

Good news is that you don't need to change your code at all. In addition, I think it is overkill to include log4j.properties and log4j.jar as part of client code for Java applet. Without them, commons logging will simply pick default Java logging and it works like a charm.
Log log = LogFactory.getLog(getClass());

The catch is to make sure to use the correct logging level. On the client side, Java logging is defined here. The default logging level is info.
C:\Program Files\Java\jdk1.6.0_20\jre\lib\logging.properties

.level= INFO
So you want to use at least log.info(), instead of log.debug(), to see anything in the Java applet console. Otherwise, the setting has to be changed in logging.properties. It is just not realistic to ask every end user to do it.

No comments:

Post a Comment