10 Replies Latest reply on Mar 14, 2006 12:58 PM by Peter Johnson

    commons-logging/log4j problem

    Andrei Pi1 Newbie

      Hi everybody, i'm using JBoss 4.0.2 and my problem is i want to use in my web app log4j over implementation of commons-logging Log4JLogger. So i created log4j.properties file in WEB-INF/classes:

      # Debug log4j
      log4j.debug=true

      log4j.rootLogger=debug, myapp

      log4j.appender.myapp=org.apache.log4j.FileAppender
      log4j.appender.myapp.layout=org.apache.log4j.HTMLLayout
      log4j.appender.myapp.layout.LocationInfo=true
      log4j.appender.myapp.layout.Title='All' Log
      log4j.appender.myapp.File=myapp.html
      log4j.appender.myapp.ImmediateFlush=true
      log4j.appender.myapp.Append=false

      In jboss-web.xml i added:
      <jboss-web>
      <class-loading java2ClassLoadingCompliance="false">
      <loader-repository>
      webtest:loader=webtest.war
      <loader-repository-config>
      java2ParentDelegation=false</loader-repository-config>
      </loader-repository>
      </class-loading>
      </jboss-web>

      I put log4j-1.2.9.jar to WEB-INF/lib.

      So what confuse me is when i use code like:

      import org.apache.log4j.Logger;
      ...
      Logger log=Logger.getLogger(TestServlet.class);
      log.debug("testing");

      everithing works fine, i get debug info from log4j how it configures logger and log file myapp.html contains my "testing" message.
      I need to use commons-logging so i use code like that:

      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      ...
      Log log=LogFactory.getLog(TestServlet.class);
      log.debug("testing");

      in this case no debug info, no log file myapp.html.?
      when i try to force log4j reading log4j.properties like:

      import org.apache.commons.logging.Log;
      import org.apache.commons.logging.LogFactory;
      import org.apache.log4j.PropertyConfigurator;
      ...
      PropertyConfigurator.configure(Thread.currentThread().getContextClassLoader(). getResource("log4j.properties"));
      Log log=LogFactory.getLog(TestServlet.class);
      log.debug("testing");
      i got debug info from log4j, log file myapp.html was created, but was empty?

      Thanks for any future reply.