Jonathon Gore Jonathon Gore -4 years ago 97
Java Question

log4j.xml file on classpath but cannot be detected by log4j

I am trying to set up log4j in a simple Java project. I keep getting the following message when running my project.

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

However I have added log4j.xml to my classpath. For example am I doing this in my main method:

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;


public class main {

private static Logger logger = LogManager.getLogger("Test");

static String convertStreamToString( is) {
java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A");
return s.hasNext() ? : "";

public static void main(String [] args) {
InputStream cl = ClassLoader.getSystemClassLoader().getResourceAsStream("log4j.xml");

When I execute this code I get the contents of my log4j.xml file, which would make it seem the the file is being loaded onto my class path properly?

Here is the content of my xml file:

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

Any ideas on what I am doing wrong?

Answer Source

Change the file name of log4j.xml to log4j2.xml.

I hope it helps.

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