简体   繁体   English

找不到log4j2配置文件

[英]log4j2 configuration file not found

I'm struggling to understand what is wrong with this issue. 我正在努力了解这个问题出了什么问题。

I have a java project (no Eclipse/Maven) structured like the following: 我有一个如下所示的Java项目(没有Eclipse / Maven):

├── build
│   ├── classes
│   │   └── oata
│   │       └── HelloWorld.class
│   └── jar
│       └── HelloWorld.jar
├── build.xml
├── lib
│   ├── log4j-api-2.3.jar
│   └── log4j-core-2.3.jar
├── myManifest
└── src
    ├── log4j2.xml
    └── oata
        └── HelloWorld.java

when building with ant I keep getting that the log4j2 config file cannot found. 使用ant进行构建时,我不断发现找不到log4j2配置文件。 I already looked at similar questions and the common issues were regarding that the xml file was not in the classpath, which is not my case. 我已经看过类似的问题,常见的问题是xml文件不在类路径中,这不是我的情况。 Anyway this is the error: 无论如何,这是错误:

[java] ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.

This is my config file 这是我的配置文件

<?xml version="1.0" encoding="UTF-8"?>
<Configuration package="oata"
status="WARN">
<Appenders>
    <Console name="Console" target="SYSTEM_OUT">
        <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
    </Console>
</Appenders>
<Loggers>
    <Logger name="oata.HelloWorld" level="trace">
        <AppenderRef ref="Console"/>
    </Logger>
    <Root level="trace">
        <AppenderRef ref="Console"/>
    </Root>
</Loggers>
</Configuration>

I am assuming you are executing java class using Ant build script. 我假设您正在使用Ant构建脚本执行Java类。

No log4j2 configuration file found means log4j2.xml configuration file is not in your classpath. No log4j2 configuration file found意味着log4j2.xml配置文件不在您的类路径中。

Please verify HelloWorld.jar includes log4j confuguration file or not. 请验证HelloWorld.jar是否包含log4j配置文件。

Alternate way set log4j confuguration file path as system property in your build script. 将构建日志中的log4j配置文件路径设置为系统属性的替代方法。

<sysproperty key="log4j.configurationFile" value="file:///${basedir}/src/log4j2.xml" />

Here is a documentation for log4j configuration . 这是log4j配置的文档。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM