Doug Hauf Doug Hauf - 1 year ago 55
Java Question

Why am i receiving the errors that I am getting?

I have this code below for a Log4j logger. I have to say that a lot of people have given me help on this on a different question. But I thought that since it was getting to a new question I would open one up.

My question is why am I getting these errors? Do I have everything configured correctly? How do I add an appender. I think that I am missing something somewhere but i am not certain as to what it is.


package TestMenu;

import org.apache.log4j.Logger;
import javax.swing.*;

public class TestLogs {
private static Logger logger = Logger.getLogger(TestLogs.class.getName());

public TestLogs() {
try {
} catch (Exception ex) {

private void LogTester() {"It works");

public static void main(String[] args) {
TestLogs tls = new TestLogs();


log4j:WARN No appenders could be found for logger (TestMenu.TestLogs).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See for more info.

Properties File:

# Root logger
log4j.rootLogger=INFO, file, stdout

# Write to file
log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

# Write to console
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n

enter image description here

xav xav
Answer Source

Log4j doesn't seem to find your configuration file. Have you tried running your application with a parameter like:


So that Log4j finds your configuration file ("config/" using System Property log4j.configuration):

enter image description here

Alternatively, you can also put this configuration file in your classpath so that Log4j finds it, like in your source directory for example:

Log4j config file location

Else, here is what Log4j documentation explains or this error message:

This occurs when the default configuration files and log4j.xml can not be found and the application performs no explicit configuration. log4j uses Thread.getContextClassLoader().getResource() to locate the default configuration files and does not directly check the file system. Knowing the appropriate location to place or log4j.xml requires understanding the search strategy of the class loader in use. log4j does not provide a default configuration since output to the console or to the file system may be prohibited in some environments. Also see FAQ: Why can't log4j find my properties in a J2EE or WAR application?

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