geek4079 geek4079 - 1 year ago 293
Java Question

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:

├── 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

when building with ant I keep getting that the log4j2 config file cannot found.
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. 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"
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
<Logger name="oata.HelloWorld" level="trace">
<AppenderRef ref="Console"/>
<Root level="trace">
<AppenderRef ref="Console"/>

Answer Source

I am assuming you are executing java class using Ant build script.

No log4j2 configuration file found means log4j2.xml configuration file is not in your classpath.

Please verify HelloWorld.jar includes log4j confuguration file or not.

Alternate way set log4j confuguration file path as system property in your build script.

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

Here is a documentation for log4j configuration.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download