15.8 Java 1.4 Logging API


Even if you aren't using Java 1.4, you've probably heard of it and the new features that it includes. One of the new features is the logging API now included with the core library. You may be wondering what the difference is between log4j and this new library, and whether you should be using that instead.

There are several similarities between log4j and the 1.4 logging implementation. However, there are also a few major differences. Let's look at the similarities first. Both log4j and the Java 1.4 logging implementation use a hierarchical namespace for the loggers. This allows you to configure loggers that basically align along your application's package structure, although this is not the only way to structure the loggers. They also both support multiple levels or priorities. The 1.4 logging implementation actually contains a few more levels than log4j, though you might not ever use the extra ones because they are so fine-grained.

The differences between the two implementations are generally not big enough to cause you to miss out on important functionality. However, it does appear that log4j offers more functionality for those that really need it. More importantly, log4j works with Java Versions 1.1 and above, while the 1.4 logging implementation works only with Version 1.4. There was talk about making it backward compatible, but that hasn't happened yet and may never happen. Also, there are currently many more appender types available for log4j than for Java 1.4, but this is not a major issue because the most important ones are present in Java 1.4.

Regardless of whether you use log4j or Java 1.4 as your logging implementation, you should leverage the Commons Logging API to protect your application from inevitable change. Coupling your application to any single third-party implementation is not recommended, in terms of logging or anything else.



Programming Jakarta Struts
Programming Jakarta Struts, 2nd Edition
ISBN: 0596006519
EAN: 2147483647
Year: 2003
Pages: 180

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net