Why isn't my portlet logging as specified in its log4j.properties?

Knowledge Base: Portlet, Logs
Submitted: August 23, 2007
Why isn't my JSR-168 portlet logging to the log file configured in its /WEB-INF/classes/log4j.properties?
A common practice in Java development is to use Apache Commons Logging as the API for logging in the portlet application, with Commons Logging discovering Log4j as the runtime logging implementation, configuring it as specified in a log4j.properties.

Commons Logging is notorious for configuration problems stemming from classloader consequences. These problems can be worked around but they often require formulaic adherence to .jar placement practices that work or deep understanding of the way application container (typically, Tomcat) classloader configuration works.

The upshot of the story is that what log4j.properties file controls depends on the placement of log4j.properties files and the placement of log4j .jar and placement of commons-logging .jar. One configuration that will work is to include both log4j .jar and commons-logging .jar in the /WEB-INF/lib of the individual portlet application and also include an intended log4.properties at /WEB-INF/classes/log4j.properties in that portlet application. This is the "every portlet for himself" approach where the portlet includes implementation .jars and configuration sufficient to do its own logging.

If your individual portlet does not include these .jars and configuration, then it may find the logging implementation .jars and configuration shared by the Tomcat application container. Depending on your intended approach for logging configuration, you may regard this as a feature. (That is, an alternative to each portlet managing and implementing its own logging is for the portlets to use shared logging implementation and configuration of the application container. Under this approach, you will not use a /WEB-INF/classes/log4j.properties in the individual portlet.)

In specific answer to the question posed by this KBA: Why isn't my portlet logging as configured in its /WEB-INF/classes/log4j.properties? The portlet may not be logging as configured because it does not include both a commons logging implementation .jar and a log4j implementation .jar in its /WEB-INF/lib directory.

PS: Even placing those .jars in the application /WEB-INF/lib directory will be insufficient if the logging .jars have been endorsed at the container layer, typically by placing them into {TOMCAT}/common/endorsed.