Jakarta Commons logging is a wrapper around Log4j (Log4jLogger), the Java native logging system(Jdk14Logger) and the built-in fall-back logger SimpleLog. Depending on which one is on the classpath, that logging system is addressed transparently via the easy-to-learn commons logging API.
Recipe:
- Create a log4j.properties such as
log4j.rootLogger=DEBUG, stdout log4j.logger.my.package.name=DEBUG log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{dd-MM HH:mm:ss,SSS} %-5p (%F:%M:%L) -%m%nFill in my.package.name; if you have a packages x.y.z1 and x.y.z2, and want to turn loggin on for both, x.y suffices. You may want to adjust the logging level as well.
- When developing web apps, make sure this file is put in
WEB-INF/classes. When developing in Eclipse, you may put it with your sources, it will be put in this directory automatically and hence deployed correctly. - Add the
commons-logging.jarand thelog4j-1.2.8.jarin yourWEB-INF/libdirectory - Add the following member variable to your class:
private static Log log = LogFactory.getLog(MyCurrentClass.class);
filling in MyCurrentClass with the class in which the logging is to be used.
- Add the
log.debug(),log.trace()etc. messages as needed.
Warning: not placing the right commons-logging.jar in the WEB-INF/lib directory can lead to mysterious behaviour 😉
See also: Jakarta Logging – commons.

No Responses