2

我已经构建了一个可执行 jar 并使用 log4j。首先我使用 Java6 构建它,它运行完美。但是当我将 JDK 更新到 1.7 版并再次构建我的项目时。似乎找不到该log4j.properties文件,因为我找不到我的日志文件和控制台中的日志格式也是错误的。

4

2 回答 2

3

Have you extracted your .JAR file to ensure that "log4j.properties" exists in the root folder? Are you sure that it is named correctly (it is named "log4j.perperties" in your question).

Troubleshooting suggestions:

  1. Run app with "-Dlog4j.debug" flag and observe log4j output
  2. Run project without "-jar" to avoid jar packaging issues (e.g. "java -cp ./xxx.jar com.pkg.AppClass")
  3. Examine encoding of the log4j.properties file
  4. Attempt manual initialization of log4j within your application, first with an external file then with the internal classpath file

I do not see any obvious JDK7 & log4j conflicts with a few minutes of googling, so it doesn't look like a "known JDK7 issue" to me.

于 2012-06-12T05:30:44.560 回答
1

我遇到了类似的问题,即使条目正确,也没有出现日志记录。后来我发现其中一个 jar 文件(jxls-reader-0.9.6.jar)有一个文件 log4j.xml,它首先被加载并用作 log4j 日志记录属性文件,因此我们没有收到日志。我已经从 jar 中删除了 log4j.xml,它工作得非常好。

您可能有类似的问题,希望它可能是类似的解决方案。

于 2012-09-13T12:43:02.983 回答