Problem with Commons Logging / Log4j setup in spring webapp with tomcat 6

I have a problem wih a logging setup in a apring webapp deployed under tomcat 6.

The webapp uses the commons-logging api, on runtime log4j should be used. The log file is created but remains empty - no log entries occur.

the setup is the following:






<log4j:configuration xmlns:log4j=''>

  <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
  <appender name="FILE" class="org.apache.log4j.RollingFileAppender">
    <param name="File" value="${catalina.home}/logs/my.log"/>

  <logger name="my.package">
    <level value="INFO"/>

    <level value="ERROR"/>
    <appender-ref ref="CONSOLE"/>
    <appender-ref ref="FILE"/>

The file logs/my.log is created, but no logs appear. The are info logs on the tomcat console, but not with the layout pattern configured.

The commons-logging-1.1.1.jar and log4j-1.2.14.jar are included in WEB-INF/lib. Any idea what is wrong here?

Asked by: Nicole220 | Posted: 28-01-2022

Answer 1

There are numerous documented instances on the web warning people about the use of commons-logging. So much so, that SLF4J is gaining a lot of popularity.

Considering that you are not interested in using Tomcat with Log4j, you should just use Log4j directly in your application. Particularly if there is no chance that you'll be switching logging frameworks in the future. It'll reduce the complexity of your application, and get rid of any class loader issues you are having with commons-logging.

This should be a relatively easy search and replace in your text, as commons-logging and log4j both use a similar call structure for their logging methods.

Answered by: Miranda698 | Posted: 01-03-2022

Answer 2

Be especially careful that you have not placed log4j.jar in the Tomcat commons/lib directory. If the root classloader loads the log4j libraries, you'll run into conflicts and initialization problems when your webapps also try to use log4j.

If you need to use log4j for common Tomcat logging, you'll need to be careful that your webapps do not attempt to load log4j as well. If you have multiple webapps on the server, then you'll need discipline that each webapp's log initialization does not stomp on the initialization of other webapps. Each webapp will need to use unique Logger IDs, which can be accomplished with unique package names.

Using a common log4j in Tomcat with multiple webapps causes serious conflicts when you have shared libraries that all want to do logging, such as Hibernate or Spring. The next webapp that attempts to initialize log4j may close the logger of the previous one. It can be a mess.

Answered by: Eric451 | Posted: 01-03-2022

Answer 3

I had similar problem and found a fix now. Start tomcat with additional parameter:


Answered by: Kirsten195 | Posted: 01-03-2022

Answer 4

You need to compile the extra component for full commons-logging. By default Tomcat 6 uses a hardcoded implementation of commons-logging that always delegates to java.util.logging.

Building instructions here

Then replace the tomcat-juli.jar in the /bin directory of Tomcat and place the tomcat-juli-adapters.jar in the /lib directory along with log4j and config.

Answered by: Catherine857 | Posted: 01-03-2022

Answer 5

if you are using log4j +common logging, you can avoid most of above configurations. common logging LogFactory have a discovery feature similar to JAXP, in following precedence, searching for Log implementations, 1. configuration attribute org.apache.commons.logging.Log inside file 2. system property org.apache.commons.logging.Log 3. If the Log4J available at class path, use the corresponding wrapper class (Log4JLogger). 4. Jdk14Logger 5. SimpleLog

just make sure, both common-logging.jar and common-logging-api.jar and log4j.jar at classpath.

Answered by: Kimberly988 | Posted: 01-03-2022

Answer 6

May be i am wrong. Please try the following:

A) Add appender to my.package as: OR B) Reduce the log leve of root to INFO

Answered by: Julian494 | Posted: 01-03-2022

Similar questions

java - Struts Logic Problem

Why doesn't the code below work? The idea is that the page checks to see if the dropdown variable has changes since you last refreshed the page. &lt;logic:equal name="Result" value = "-1"&gt; &lt;bean:define id="JOININGDATE" name="smlMoverDetailForm" property="empFDJoiningDate" type="java.lang.String" toScope = "session" /&gt; &lt;/logic:equal&gt; &lt;logic:equal name="Result" value = "-1"...

java - Problem with applet loading on Mac OS x 10.4

I have been working on web application which includes java applet. My app is working fine on PC with different browsers like IE and Firefox. The web application hosted on Linux (Ubuntu). I had problem on Mac with Firefox. I was unable to load the applet. This is the error i found in java console. Java.lang.classNotFoundException web/applets/ImageObsApplet.class I have hosted the web application on PC windows ...

java - Help I have problem with select query in JPA

i have problem i want to select name_magazine from magazine and i already import all library needed and Query q = EntityManger.createQuery ("SELECT name_magazine FROM Magazine"); List results = (List) q.getResultList (); For(Sting s : result) System.out.println(s); but when i run this code it's error. can someone help...

java - AOP problem running Spring unit tests

I have a Spring web application which is configured to use JDK proxying for AOP. The AOP annotations (such as @Transactional) are declared on the interfaces, rather than the implementation classes. The application itself works fine, but when I run the unit tests, it seems to be attempting to use CGLIB for the AOP functionality (instead of JDK proxying). This causes the tests to fail - I've appended the stack trace ...

Problem running Java .war on Tomcat

I am following the tutorial here: Crawling works fine, as does the test search from the command line. When I try to fire up tomcat after moving ROOT.war into place(and it unarchiving and creating a new ROOT folder during startup), I get a page with the 500...

java - Problem with number of rows in a dataset

My new problem is the following: an SQL query to a database (DB2) returns 1500 rows but BIRT shows me only 500 in the dataset-editor. To count them I used a computed column (Integer) with the following logic: Total.count(row["VPK"]) I'm using the RCP-Designer (BIRT 2.1.3). How can i get the other rows as well?

java - Problem with threads

*I'm using Java. I have this thread, agent, that explores a room to determine its size and clean it if it's dirty. Then I have the interface, which draws the agent as it explores the environment. Agent is subclassed from Thread, and Java takes care of managing the threads. All I do is create the thread and say object.start(). This works very well under normal circustances. However, the menus are enabled dur...

java - JSF JSTL problem with nested forEach

Inside a nested foreach, accessing the same variable is returning different values. This happens when the page is reloaded, not on first load. &lt;ui:composition xmlns="" (...) xmlns:c="" xmlns:h=""&gt; (...) &lt;c:forEach items="#{controller.availableTransitions}" var="transition"&gt; &lt;c:forEach items=...

Java Swing Problem

I have a board with cards in which I have to find matches. I have two variables buttonA and buttonB to keep track of the squares clicked. When they are equal I can remove them from the board by simply adding this code: cards[buttonA].setVisible(false); cards[buttonB].setVisible(false); How can I place the same image on all the buttons after finding matches...

Java and MySQL date problem

I do a rs.getTimestamp("datetime") in Java. In the database, this datetime is 2009/03/06 02:47:18 but the time is returned as 14:47:18 I'm not very knowledgeable about MySQL dates, so I would appreciate any explanation as to why this is happening.

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)