Log4J Setup

I am unable to execute unit tests in IntelliJ and have the logging output show up properly. I am using commons logging with log4j, but am unable to get it to identify that I am using log4j (via LogFactory.getLog()), even though it is in my classpath. It keeps defaulting to the Java 1.4 logger. Any thoughts?


C:\Sun\jdk1.5.0_12\bin\java -Didea.launcher.port=7537 "-Didea.launcher.bin.path=C:\Program Files\JetBrains\IntelliJ IDEA 7.0.3\bin"
-Dfile.encoding=windows-1252 -classpath "C:\Sun\jdk1.5.0_12\jre\lib\charsets.jar;C:\Sun\jdk1.5.0_12\jre\lib\deploy.jar;
C:\Sun\jdk1.5.0_12\jre\lib\javaws.jar;C:\Sun\jdk1.5.0_12\jre\lib\jce.jar;C:\Sun\jdk1.5.0_12\jre\lib\jsse.jar;
C:\Sun\jdk1.5.0_12\jre\lib\plugin.jar;C:\Sun\jdk1.5.0_12\jre\lib\rt.jar;C:\Sun\jdk1.5.0_12\jre\lib\ext\dnsns.jar;
C:\Sun\jdk1.5.0_12\jre\lib\ext\localedata.jar;C:\Sun\jdk1.5.0_12\jre\lib\ext\sunjce_provider.jar;C:\Sun\jdk1.5.0_12\jre\lib\ext\sunpkcs11.jar;
C:\project\classes;C:\Program Files\JetBrains\IntelliJ IDEA 7.0.3\lib\junit-4.4.jar;C:\project\lib\runtime\ojdbc14.jar;
C:\project\lib\runtime\commons-collections.jar;C:\project\lib\runtime\ProjectSharedDomain-1.5.jar;C:\project\lib\runtime\webservices.jar;
C:\project\lib\runtime\ehcache-1.3.0.jar;C:\project\lib\runtime\dom4j-1.6.1.jar;C:\project\lib\runtime\spring-aop.jar;
C:\project\lib\runtime\cglib-nodep-2.1_3.jar;C:\project\lib\runtime\commons-lang.jar;C:\project\lib\runtime\spring-webmvc.jar;
C:\project\lib\runtime\commons-discovery-0.2.jar;C:\project\lib\runtime\spring.jar;C:\project\lib\runtime\log4j-1.2.14.jar;
C:\project\lib\runtime\clover.jar;C:\project\lib\runtime\spring-modules-validation.jar;C:\project\lib\runtime;C:\project\lib\runtime\hibernate3.jar;
C:\project\lib\runtime\spring-test.jar;C:\project\lib\runtime\sitemesh-2.3.jar;C:\project\lib\runtime\axis.jar;C:\project\lib\runtime\spring-web.jar;
C:\project\lib\runtime\commons-logging.jar;C:\project\lib\runtime\commons-beanutils.jar;C:\project\lib\runtime\webservices-security.jar;
C:\project\lib\runtime\ProjectWsClient-1.1.jar;C:\project\lib\runtime\antlr-2.7.6.jar;C:\project\lib\tomcat\wsexception.jar;
C:\project\lib\tomcat\ras.jar;C:\project\lib\tomcat;C:\project\lib\tomcat\standard.jar;
C:\project\lib\tomcat\jstl.jar;C:\project\lib\tomcat\bootstrap.jar;C:\project\lib\tomcat\jta.jar;C:\project\lib\tomcat\wsdl4j.jar;
C:\project\lib\tomcat\emf.jar;C:\project\lib\buildtime\xercesImpl.jar;C:\project\lib\buildtime;C:\project\lib\buildtime\objectpoolimpl.jar;
C:\project\lib\buildtime\com.ibm.ws.webservices.thinclient_6.1.0.jar;C:\project\lib\buildtime\dbdeploy.jar;C:\project\lib\buildtime\xml-apis.jar;
C:\project\lib\buildtime\clover.jar;C:\project\lib\buildtime\hamcrest-all-1.1.1.jar;C:\project\lib\buildtime\javaee.jar;
C:\project\lib\buildtime\channel.http.jar;C:\project\lib\buildtime\easymock.jar;
C:\Documents and Settings\u0057716\.IntelliJIdea70\config\plugins\clover-idea7.jar;
C:\Program Files\JetBrains\IntelliJ IDEA 7.0.3\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain
com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 -junit4 com.project.util.validator.EmailValidatorTest,blank

Edited by: kwikgoal on Apr 3, 2008 1:21 AM

4 comments
Comment actions Permalink

In your default Junit run configuration, define a VM Parameter like so:

-Dlog4j.configuration=file:///path/to/your/log4j.properties

Note that the value for this parameter is a file URL (not a file path). Log4j checks this system property for retrieving its configuration file. It's a feature of log4j -- not IDEA -- so setting this system variable is applicable to other environments as well. Further, having this same property defined in your IDEA Tomcat run configuration will have the same effect.

HTH!

Keith

0
Comment actions Permalink

I am sure this is it, I am just doing something wrong now. Is this a relative or absolute file path? It still doesn't pick it up with the formats that I tried...

0
Comment actions Permalink

It isn't a file path at all, but a file URL. Are you on Windows? If so, I believe the parameter's value would be something like:

file://C:/configuration/log4j.properties

If your log4j properties file is located in c:\configuration and is named log4j.properties.

If you're on unix, and your properties file is in /home/daffy/conf and is named "log4j.properties", the value would be:

file:///home/daffy/conf/log4j.properties

Let me know if you have further problems.

0
Comment actions Permalink

It is Windows...and I still could not get it to work with the patterns suggested (or any of a number of others). No matter what, it kept applying the org.apache.commons.logging.impl.Jdk14Logger to the Log object.

I then found this on the Apache Commons Logging site:

Creating a Log Implementation
The minimum requirement to integrate with another logger is to provide an implementation of the org.apache.commons.logging.Log interface. In addition, an implementation of the org.apache.commons.logging.LogFactory interface can be provided to meet specific requirements for connecting to, or instantiating, a logger. The default LogFactory provided by JCL can be configured to instantiate a specific implementation of the org.apache.commons.logging.Log interface by setting the property of the same name (org.apache.commons.logging.Log). This property can be specified as a system property, or in the commons-logging.properties file, which must exist in the CLASSPATH.

Creating the file commons-logging.properties file with the single line worked: org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

It now uses Log4J. I still don't understand why the discovery process of of Commons logging was not working. According to the docs, #3 should have been run before #4:

...
2) Look for a system property named org.apache.commons.logging.Log (for backwards compatibility to pre-1.0 versions of this API, a system property org.apache.commons.logging.log is also consulted).
3) If the Log4J logging system is available in the application class path, use the corresponding wrapper class (Log4JLogger).
4) If the application is executing on a JDK 1.4 system, use the corresponding wrapper class (Jdk14Logger).
...

Is it some sort of bug with Commons Logging and/or IntelliJ? I have no idea. Any way, it works now. Thanks for all the help!

0

Please sign in to leave a comment.