Dec 10

In the past developers have used log4j, and Java’s built in logging framework api. Commons logging (JCL) has also been used as a facade to allow easy implementation switching.

Now we also have logback, and the slf4j facade.

So the question is what should we be using to implement logging in our Java application?

Firstly using a facade is recommended. It allows you to far more easily switch the underlying logging implementation without affecting your application code. JCL suffered from a variety of classloader issues that made it troublesome to use. SLF4J has none of these issues and works well as a logging facade and is currently our facade of choice.

For the logging implementation we have long used log4j and it does a good job of providing simple logging capabilities. Our preferred logging framework for new projects however is logback. It includes many improvements over log4j such as:

  • faster
  • more flexible configurations
  • filters
  • implements SLF4J natively

written by objects \\ tags: , , , , , ,

Jul 18

The default logging configuration that ships with Tomcat 6.0 logs to both catalina.out and also a daily log catalina.yyyy-mm-dd.log. The daily log starts a new file everyday, but catalina.out just continues to grow until your disk fills up.

To make things worse if you want to purge catalina.out you need to restart tomcat to free up the disk space used as tomcat holds the file open.

To avoid this situation what you can do is remove the logging to catalina.out (by removing the handler). This can be achieved by editting conf/logging.properties and changing:

.handlers = 1catalina.org.apache.juli.FileHandler, java.util.logging.ConsoleHandler

to

.handlers = 1catalina.org.apache.juli.FileHandler

written by objects \\ tags: , ,

Apr 05

Writing to the Firebug console can be done using
console.log("Hello World");

As well as a log() method there are also debug(), info(), warn() and error() methods which the log message gets suitably color coded in the Firebug console.

The methods all support printf style formatting

console.log("Received %d messages", messageCount);

written by objects \\ tags: , , ,