问题描述
$ java -Dlog4j.configuration=file:///path/to/your/log4j2.xml -jar /path/to/your/jar_file.jar
写信给控制台,你得到
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
但是,看起来还已经找到了配置文件,并且无法可简化:
log4j:WARN Continuable parsing error 2 and column 31 log4j:WARN Document root element "Configuration", must match DOCTYPE root "null". log4j:WARN Continuable parsing error 2 and column 31 log4j:WARN Document is invalid: no grammar found. log4j:ERROR DOM element is - not a <log4j:configuration> element. log4j:WARN No appenders could be found for logger (kafka.utils.VerifiableProperties). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
推荐答案
我已经处理这个问题已有一段时间了.我已经改变了本文中所述的所有内容,甚至发生了思想错误.在这种情况下,请确保在更改.xml或.properties文件中更改设置时清洁项目. 在日食环境中.选择项目 - >清洁
其他推荐答案
问题1
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
解决方案1
使用log4j aka" log4j2"的版本2
-Dlog4j.configuration=
应该阅读
-Dlog4j.configurationFile=
- 1.2手册: .html
- 2.x手册:/LOG4J/2.x/manual/configuration.html
问题2
log4j:WARN ....
解决方案2
在您的项目中,Unimcude log4j-1.2 jar,而是包含log4j-1.2-api-2.1.jar.我不确定如何确切排除Log4J 1.2.我知道我的项目需要什么依赖性.因此,有了一些阅读,我排除了很多东西.
<dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka_2.10</artifactId> <version>0.8.2.0</version> <exclusions> <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> </exclusion> <exclusion> <groupId>org.apache.log4j</groupId> <artifactId>log4j-core</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency>
我不确定哪个排除措施的技巧.另外,我包括了对1.2 API的依赖性,该API桥接到2.x.
.<!-- http://logging.apache.org/log4j/2.0/manual/migration.html http://logging.apache.org/log4j/2.0/maven-artifacts.html Log4j 1.x API Bridge If existing components use Log4j 1.x and you want to have this logging routed to Log4j 2, then remove any log4j 1.x dependencies and add the following. --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-1.2-api</artifactId> <version>2.2</version> </dependency>
现在,仅进入控制台的1.2日志实际上流到了我们的2.x附录.
其他推荐答案
如果您没有log4j-1.2.2.jar的财富,则 renko在他的评论中指出/a>,您将仅查看找到消息 no log4j2配置文件.
如果您的配置文件中存在错误,这是一个问题,因为您不会被告知问题在启动时的位置.
例如,如果您有一个log4j2.yaml文件,则log4j2无法处理,例如,您尚未为项目配置yaml解析器,否则您的配置只是不正确.您将遇到 no log4j2配置文件消息,而没有其他信息.即使您有一个有效的log4j2.xml文件,也是这种情况,因为log4j2只会尝试处理它找到的第一个配置文件.
我找到了调试问题的最佳方法是明确说明您希望根据命令行参数使用的配置文件-log4j2-configuration-file-file-using-use-default-figuration-figuration-logging-only-er'>上面.
-Dlog4j.configurationFile=
希望这将帮助您查明是否实际上是由您的classloader引起的.
更新
您还可以使用以下属性来更改状态记录器的默认级别以获取更多信息:
-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=<level>
问题描述
$ java -Dlog4j.configuration=file:///path/to/your/log4j2.xml -jar /path/to/your/jar_file.jar
Written to the console, you get
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
But, it also looks like the configuration file has been found and was not parsable:
log4j:WARN Continuable parsing error 2 and column 31 log4j:WARN Document root element "Configuration", must match DOCTYPE root "null". log4j:WARN Continuable parsing error 2 and column 31 log4j:WARN Document is invalid: no grammar found. log4j:ERROR DOM element is - not a <log4j:configuration> element. log4j:WARN No appenders could be found for logger (kafka.utils.VerifiableProperties). log4j:WARN Please initialize the log4j system properly. log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
推荐答案
I have been dealing with this problem for a while. I have changed everything as described in this post and even thought error occured. In that case make sure that you clean the project when changing settings in .xml or .properties file. In eclipse environment. Choose Project -> Clean
其他推荐答案
Problem 1
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
Solution 1
To work with version 2 of log4j aka "log4j2"
-Dlog4j.configuration=
should read
-Dlog4j.configurationFile=
- 1.2 manual: http://logging.apache.org/log4j/1.2/manual.html
- 2.x manual: http://logging.apache.org/log4j/2.x/manual/configuration.html
Problem 2
log4j:WARN ....
Solution 2
In your project, uninclude the log4j-1.2 jar and instead, include the log4j-1.2-api-2.1.jar. I wasn't sure how exactly to exclude the log4j 1.2. I knew that what dependency of my project was requiring it. So, with some reading, I excluded a bunch of stuff.
<dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka_2.10</artifactId> <version>0.8.2.0</version> <exclusions> <exclusion> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> </exclusion> <exclusion> <groupId>org.apache.log4j</groupId> <artifactId>log4j-core</artifactId> </exclusion> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency>
I am not sure which of the exclusions did the trick. Separately, I included a dependency to the 1.2 api which bridges to 2.x.
<!-- http://logging.apache.org/log4j/2.0/manual/migration.html http://logging.apache.org/log4j/2.0/maven-artifacts.html Log4j 1.x API Bridge If existing components use Log4j 1.x and you want to have this logging routed to Log4j 2, then remove any log4j 1.x dependencies and add the following. --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-1.2-api</artifactId> <version>2.2</version> </dependency>
Now, the 1.2 logs which were only going to the console actually flow to our 2.x appenders.
其他推荐答案
If you don't have the fortune of the log4j-1.2.jar on your classpath as Renko points out in his comment, you will only see the message no log4j2 configuration file found.
This is a problem if there is an error in your configuration file, as you will not be told where the problem lies upon start-up.
For instance if you have a log4j2.yaml file which log4j2 fails to process, because for example, you have not configured a YAML parser for your project, or your config is simply incorrect. You will encounter the no log4j2 configuration file found message, with no further information. This is the case even if you have a valid log4j2.xml file, as log4j2 will only attempt to process the first configuration file it finds.
I've found the best way to debug the problem is to explicitly state the configuration file you wish to use as per the command line argument mentioned above.
-Dlog4j.configurationFile=
Hopefully this will help you pinpoint if the issue is actually caused by your classloader not finding the log4j2 configuration file or something else in your configuration.
Update
You can also use the below property to change the default level of the status logger to get further information:
-Dorg.apache.logging.log4j.simplelog.StatusLogger.level=<level>