简体   繁体   English

是什么原因导致Log4JLogger无法找到或无法使用?

[英]Whats the root cause of Log4JLogger' cannot be found or is not useable?

I have commons-logging.jar (v1.0.4) and log4j-1.2.8.jar in the classpath and getting following run-time error: 我在类路径中有commons-logging.jar(v1.0.4)和log4j-1.2.8.jar,并且遇到以下运行时错误:

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)

If you using Maven, you must ensure declare commons-logging and log4j in pom.xml 如果您使用Maven,则必须确保在pom.xml中声明commons-logging和log4j

<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 如果你只声明公共 - 记录你得到错误Log4JLogger cannot be found or is not useable

This was a classpath problem and we did have another version of log4j in the classpath. 这是一个类路径问题,我们在类路径中确实有另一个版本的log4j。 Thanks Nathan Ryan ! 谢谢Nathan Ryan!

Had this problem using log4j-2.x with commons-logging-1.2. 有这个问题使用log4j-2.x与commons-logging-1.2。 Reverted back to log4j 1.2.x and all is fine with the world. 恢复到log4j 1.2.x并且对世界来说一切都很好。

I see this error sometimes when I try to run a web application on tomcat 7 in my eclipse 3.6 . 当我尝试在我的eclipse 3.6中运行tomcat 7上的Web应用程序时,有时会看到此错误。 It occurs out of nowhere just by restarting eclipse. 它只是通过重启eclipse而无处不在。

After several (!) "clean all projects" and new deployments of the web app on the server the application runs again. 在服务器上的几个(!)“清理所有项目”和Web应用程序的新部署之后,应用程序再次运行。 Maybe someone else knows the exact "spell" to solve this mystery without trial and error? 也许其他人知道确切的“咒语”来解决这个谜,没有反复试验?

If you are providing an implementation for a logger, the implementation must define a constructor that takes a java.lang.String as an argument. 如果要为记录器提供实现,则实现必须定义一个将java.lang.String作为参数的构造函数。 Otherwise you get an "org.apache.commons.logging.LogConfigurationException: User-specified log class '...' cannot be found or is not useable." 否则,您将收到“org.apache.commons.logging.LogConfigurationException:用户指定的日志类'...'无法找到或无法使用。” The faq page of the apache wiki states so. apache维基的常见问题页面如此说明。

Are you creating any specific project like web-services or spring, etc? 您是否正在创建任何特定项目,如Web服务或弹簧等? If yes, then please analyze the project specific property files which would have a property in reference to the Logger, something like 如果是,那么请分析项目特定的属性文件,这些文件将具有引用Logger的属性,例如

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

if you have a java project with servlets. 如果你有一个带servlet的java项目。

I received this same exception. 我收到了同样的例外。

I do have an implementation of logger. 我有一个logger的实现。

It did not have a constructor that takes a String as an argument. 它没有将String作为参数的构造函数。

I implemented such a constructor and that solved the problem for me. 我实现了这样的构造函数,并为我解决了这个问题。

I was getting this error when apache commons logging jar was there in my classpath but log4j jar was somehow missing. 当apache commons登录jar在我的类路径中但是log4j jar在某种程度上丢失时,我收到了这个错误。 Once I added log4j jar to my class path, this error was gone. 一旦我将log4j jar添加到我的类路径,这个错误就消失了。

There is an answer here Commons-logging with log4j2 这里有一个答案Commons-logging with log4j2

Include the library: 包括图书馆:
log4j-jcl
See also: 也可以看看:
https://logging.apache.org/log4j/2.x/faq.html#which_jars https://logging.apache.org/log4j/2.x/faq.html#which_jars

This error seems to be pretty generic. 这个错误似乎非常通用。 To get more details, start up the JVM with this option: 要获取更多详细信息,请使用以下选项启动JVM:

-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. 将log4j.jar添加到类路径修复了该问题。

I was facing this problem and found out that it was due to a classpath conflict related to log4j jar. 我遇到了这个问题,发现它是由于与log4j jar相关的类路径冲突造成的。 As I was using maven in my project, the fix was to add a dependency management for log4j as below. 当我在我的项目中使用maven时,修复是为log4j添加依赖关系管理,如下所示。

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
            <type>jar</type>
            <scope>compile</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Weblogic11:用户指定的日志类&#39;org.apache.commons.logging.impl.Log4JLogger&#39;找不到或无法使用 - Weblogic11: User-specified log class 'org.apache.commons.logging.impl.Log4JLogger' cannot be found or is not useable 在WildFly中重新部署ESAPI应用程序时,ClassCastException Log4JLogger无法转换为Logger - ClassCastException Log4JLogger cannot be cast to Logger when redeploying ESAPI application in WildFly 在Websphere 8.5.01上部署时,Log4JLogger不实现日志 - Log4JLogger does not implement Log when deploying on websphere 8.5.01 PDFBox 合并命令工具与 Log4JLogger 的问题 - PDFBox merge command tool problem with Log4JLogger Wildfly 17:“找不到或无法使用用户指定的日志类&#39;org.apache.commons.logging.impl.Log4JLogger”。”使用commons-configuration2 - Wildfly 17: “User-specified log class 'org.apache.commons.logging.impl.Log4JLogger' cannot be found or is not useable.” using commons-configuration2 扩展 Log4JLogger 并在运行时调用子类 - Extend Log4JLogger and invoke subclass during runtime Sbt test: class org.apache.logging.slf4j.Log4jLogger cannot be cast to class ch.qos.logback.classic.Logger (org.apache.logging.slf4j.Log4jLogger - Sbt test: class org.apache.logging.slf4j.Log4jLogger cannot be cast to class ch.qos.logback.classic.Logger (org.apache.logging.slf4j.Log4jLogger 如何在OSGi中找到类未找到问题的根本原因? - How can I find the root cause for class not found issue, in OSGi? java.lang.ClassNotFoundException:net.spy.memcached.compat.log.SLF4JLogger - java.lang.ClassNotFoundException: net.spy.memcached.compat.log.SLF4JLogger 找不到log4j.properties - log4j.properties cannot be found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM