12

I have commons-logging.jar (v1.0.4) and log4j-1.2.8.jar in the classpath and getting following run-time error:

Caused by: org.apache.commons.logging.LogConfigurationException: User-specified log class 'org.apache.commons.logging.impl.Log4JLogger' cannot be found or is not useable.
    at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:874)
    at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:604)
    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:336)
    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:310)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:685)
Debajyoti Roy
  • 985
  • 2
  • 12
  • 34

10 Answers10

15

If you using Maven, you must ensure declare commons-logging and log4j in pom.xml

<dependencies>
    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.3</version>
    </dependency>
    <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.17</version>
    </dependency>
</dependencies>

if you declare only commons-logging you with getting error Log4JLogger cannot be found or is not useable

searching9x
  • 1,515
  • 16
  • 16
5

This was a classpath problem and we did have another version of log4j in the classpath. Thanks Nathan Ryan !

Debajyoti Roy
  • 985
  • 2
  • 12
  • 34
3

Had this problem using log4j-2.x with commons-logging-1.2. Reverted back to log4j 1.2.x and all is fine with the world.

James Boutcher
  • 2,593
  • 1
  • 25
  • 37
  • As I don't want to revert back to log4j 1.2.X i found another solutions which worked for me. In log4j 1.2.X you used to have the file comons-logging.properties in the classpath with the content: `org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger` With log4j2 I only had to remove this file and the error was gone. This simple solution might also help you. – OASE Software GmbH Jun 26 '23 at 08:39
3

There is an answer here Commons-logging with log4j2

Include the library:
log4j-jcl
See also:
https://logging.apache.org/log4j/2.x/faq.html#which_jars

Max Robbertze
  • 406
  • 4
  • 11
2

I see this error sometimes when I try to run a web application on tomcat 7 in my eclipse 3.6 . It occurs out of nowhere just by restarting eclipse.

After several (!) "clean all projects" and new deployments of the web app on the server the application runs again. Maybe someone else knows the exact "spell" to solve this mystery without trial and error?

Bruno Eberhard
  • 1,624
  • 16
  • 22
1

If you are providing an implementation for a logger, the implementation must define a constructor that takes a java.lang.String as an argument. Otherwise you get an "org.apache.commons.logging.LogConfigurationException: User-specified log class '...' cannot be found or is not useable." The faq page of the apache wiki states so.

Are you creating any specific project like web-services or spring, etc? If yes, then please analyze the project specific property files which would have a property in reference to the Logger, something like

<property name="logger">javax.servlet,org.apache.commons.logging</property>

if you have a java project with servlets.

mtk
  • 13,221
  • 16
  • 72
  • 112
  • we don't have our implementation of Logger so eliminate that being the issue. its a core-java application running in its own jvm – Debajyoti Roy May 22 '12 at 14:10
  • ok. Please give more info about your problem the stack-trace, minimal working code, etc – mtk May 22 '12 at 15:09
1

I received this same exception.

I do have an implementation of logger.

It did not have a constructor that takes a String as an argument.

I implemented such a constructor and that solved the problem for me.

Tom W
  • 31
  • 5
1

I was getting this error when apache commons logging jar was there in my classpath but log4j jar was somehow missing. Once I added log4j jar to my class path, this error was gone.

Shiv
  • 21
  • 2
1

This error seems to be pretty generic. To get more details, start up the JVM with this option:

-Dorg.apache.commons.logging.diagnostics.dest=STDOUT

In my case, found some missing dependencies.

[LogFactoryImpl@929338653 from sun.misc.Launcher$AppClassLoader@1442407170] Attempting to instantiate 'org.apache.commons.logging.impl.Log4JLogger'
[LogFactoryImpl@929338653 from sun.misc.Launcher$AppClassLoader@1442407170] Trying to load 'org.apache.commons.logging.impl.Log4JLogger' from classloader sun.misc.Launcher$AppClassLoader@1442407170
[LogFactoryImpl@929338653 from sun.misc.Launcher$AppClassLoader@1442407170] Class 'org.apache.commons.logging.impl.Log4JLogger' was found at 'jar:file:/home/mcadiz/NetBeansProjects/LogFilter/dist/lib/commons-logging-1.2.jar!/org/apache/commons/logging/impl/Log4JLogger.class'
[LogFactoryImpl@929338653 from sun.misc.Launcher$AppClassLoader@1442407170] The log adapter 'org.apache.commons.logging.impl.Log4JLogger' is missing dependencies when loaded via classloader sun.misc.Launcher$AppClassLoader@1442407170: org/apache/log4j/Priority
Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.apache.commons.logging.LogConfigurationException: User-specified log class 'org.apache.commons.logging.impl.Log4JLogger' cannot be found or is not useable.
    at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:804)
    at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:541)
    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:292)
    at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:269)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:655)
    at com.oracle.logfilter.LogEntry.<clinit>(LogEntry.java:19)

Adding the log4j.jar to the classpath fixed the issue.

Mario.Cadiz
  • 178
  • 12
0

I was facing this problem and found out that it was due to a classpath conflict related to log4j jar. As I was using maven in my project, the fix was to add a dependency management for log4j as below.

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
aimhaj
  • 1,615
  • 1
  • 11
  • 16