【问题标题】:Undefined trace method for Log4JLog4J 的未定义跟踪方法
【发布时间】:2013-07-23 18:24:55
【问题描述】:

我的 Maven(版本 3.1.0)项目中出现奇怪的编译错误。我在我的 POM 中添加了以下依赖项:

<dependency>
    <groupId>log4j</groupId>
    <artifactId>log4j</artifactId>
    <version>1.2.17</version>
</dependency>

当我使用以下代码时,我收到 The method trace(String) is undefined for type Logger 错误。

import org.apache.log4j.Logger;
...
private static Logger logger = Logger.getLogger(Main.class);
...
logger.trace("message to be traced");

如果我使用例如不过,调试而不是跟踪,代码编译得很好。

可能有什么问题?

如果我遗漏了一些重要信息,请随时在 cmets 中询问。我会立即添加它们。


当我运行建议的mvn dependency:tree 命令时,我得到以下输出。

biz.jezek:inscsdbdt:jar:1.0
+- com.sun.xml.ws:jaxws-rt:jar:2.1.3:compile
|  +- javax.xml.ws:jaxws-api:jar:2.1:compile
|  |  \- javax.xml.bind:jaxb-api:jar:2.1:compile
|  +- com.sun.xml.bind:jaxb-impl:jar:2.1.6:compile
|  +- com.sun.xml.messaging.saaj:saaj-impl:jar:1.3:compile
|  |  \- javax.xml.soap:saaj-api:jar:1.3:compile
|  +- com.sun.xml.stream.buffer:streambuffer:jar:0.7:compile
|  |  \- javax.activation:activation:jar:1.1:compile
|  +- com.sun.xml.stream:sjsxp:jar:1.0:compile
|  |  \- javax.xml.stream:stax-api:jar:1.0:compile
|  +- org.jvnet.staxex:stax-ex:jar:1.2:compile
|  +- com.sun.org.apache.xml.internal:resolver:jar:20050927:compile
|  \- org.jvnet:mimepull:jar:1.1:compile
+- log4j:log4j:jar:1.2.17:compile
+- biz.jezek:jdt:jar:1.0:compile
+- biz.jezek:utils:jar:1.0-SNAPSHOT:compile
|  +- biz.jezek:dmsclient:jar:10.0.1:compile
|  \- biz.jezek:umsjavaclient:jar:10.0.1:compile
+- com.microsoft:sqljdbc:jar:4:compile
+- commons-lang:commons-lang:jar:2.6:compile
+- org.aspectj:aspectjrt:jar:1.6.7:compile
+- junit:junit:jar:4.8.2:test (scope not updated to compile)
\- org.mockito:mockito-all:jar:1.8.4:test

【问题讨论】:

  • 进口怎么样?
  • 我已经更新了sn-p的代码。我只导入 Logger 类,但这对我来说似乎没问题。
  • 能否运行mvn dependency:tree -DoutputFile=DT.log 并发布DT.log 内容?

标签: java maven log4j


【解决方案1】:

在您的记录器上检查 isTraceEnabled()。这可以让您查看是否启用了

log4j.rootLogger=TRACE

也见Log4j | Updating the Log Level for the Appender

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-27
    • 1970-01-01
    • 2018-05-26
    • 1970-01-01
    • 2018-11-02
    • 1970-01-01
    • 2012-01-29
    • 1970-01-01
    相关资源
    最近更新 更多