4 Replies Latest reply on Nov 15, 2004 11:54 AM by Toni Mecha

    need log4j category to work in my webapp

    mazz Master

      I hate to ask a Log4J configuration question (mainly because the answer usually illicits a "duh" upon hearing it) but for the life of me I can't get this to work. I've read the Wiki pages and searched around but nothing I tried seems to work.

      I have a webapp that has a class that wants to output a log message. In log4j.xml in the conf directory, I add:

      <category name="com.hp">
       <priority value="INFO"/>

      (I even tried using the Log4J 1.2 way with the [logger> settings, in addition to [category>).

      This is the way I create the logger (notice it uses Apache commons logging):

      private static final org.apache.commons.logging.Log LOG = org.apache.commons.logging.LogFactory.getLog(com.hp.test.MyClass.class);

      But that logger implementation comes back as a NoOpLog. I have no idea why or how. But, since it is a NoOpLog, then obviously irregardless of whether I do LOG.debug() or up to LOG.fatal(), nothing is going to happen.

      Some additional info: I tried putting a log4j.properties in WEB-INF/classes - didn't work. I tried copying my log4j.xml to WEB-INF/classes and that didn't work.

      Any tips are appreciated.


        • 1. Re: need log4j category to work in my webapp
          mazz Master

          This is to make this entry complete (and hopefully help someone else avoid spending the time I did trying to solve this). It turns out I needed a commons-logging.properties file in my war's WEB-INF/classes directory. It has a single entry like this:


          I need this (I think) because the Unified classloader was picking up a commons-logging.properties file located in ebxmlrr-service.sar\ebxmlrr.war\WEB-INF\classes that looks like this:


          I am surprised alot of other people haven't run into this. I was unable to use commons logging in any WAR or SAR that I deploy without overriding the commons-logging.properties file. If I don't do this, my default logger ended up being NoOpLog which eats up all log messages, effectively making everything quiet.

          I would think this default behavior should be changed - or otherwise documented somewhere (I could not find the answer to this problem anywhere; maybe I missed it?)

          • 2. Re: need log4j category to work in my webapp
            peter neville Newbie

            Totally agree with you on documenting this one. Would love to see it in the Wiki.
            Thanks - you saved me some time here!

            • 3. Re: need log4j category to work in my webapp
              Scott Stark Master

              Wikis are editable by anyone with a valid login so take a look at updating:


              • 4. Re: need log4j category to work in my webapp
                Toni Mecha Newbie

                I had this same problem trying to debug jgroups in jboss 4.0.0, which didn't work till I removed the commons-logging.properties from the ebxmlrr folders.

                Lot's of thanks - you saved me time here too!