geek4079
geek4079

Reputation: 579

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
        └── HelloWorld.java

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"
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>

Upvotes: 1

Views: 17393

Answers (1)

Amit Bhoraniya
Amit Bhoraniya

Reputation: 621

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.

Upvotes: 7

Related Questions