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

Last updated
App Shah

Crunchify » Eclipse IDE Tutorials » ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console

sample log4j2.xml file example

Maven dependencies are magic. Are you running Maven Java Project and using log4j into your project? Have you added below to your project’s pom.xml file? Probably the easiest way to get logging into your java application is with log4j from Apache.

<dependency>
	<groupId>org.apache.logging.log4j</groupId>
	<artifactId>log4j-core</artifactId>
	<version>2.16.0</version>
</dependency>

Well you have to add log4j2.xml file to your project’s resource folder in order for log4j to run correctly with your project.

Update Log4j to latest version

CVE-2021-44228: Apache Log4j2 <=2.14.1 JNDI features used in configuration, log messages, and parameters do not protect against attacker controlled LDAP and other JNDI related endpoints.

From log4j 2.16.0, this behavior has been disabled by default.

Another must readHow to configure log4j.properties correctly – log4j Sample Program

I recently got below error while running program.

log4j2 configuration file missing

Well, a solution is  simple

Add below log4j2.xml simple configuration file under src/main/resources folder.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">

<!-- Author:  crunchify.com  -->
	<Appenders>
		<Console name="Console" target="SYSTEM_OUT">
			<PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" />
		</Console>

		<RollingFile name="RollingFile" filename="log/CrunchifyTest.log"
			filepattern="${logPath}/%d{YYYYMMddHHmmss}-fargo.log">
			<PatternLayout pattern="%d{YYYY-MM-dd HH:mm:ss} [%t] %-5p %c{1}:%L - %msg%n" />
			<Policies>
				<SizeBasedTriggeringPolicy size="100 MB" />
			</Policies>
			<DefaultRolloverStrategy max="20" />
		</RollingFile>

	</Appenders>
	<Loggers>
		<Root level="info">
			<AppenderRef ref="Console" />
			<AppenderRef ref="RollingFile" />
		</Root>
	</Loggers>
</Configuration>

Try running your program again and you shouldn’t see this issue anymore. Hope this helps.

6 thoughts on “ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console”

  1. Good post. Thanks for sharing.

    One important point:

    The pattern starting with ‘YYYY’ is throwing an IllegalArgumentException.

    To solve this just replace all instances of ‘YYYY’ with ‘yyyy’.

    1.

    2. filepattern=”${logPath}/%d{yyyyMMddHHmmss}-fargo.log”>

    3.

    Reply

Leave a Comment