Java – Log4J properties file not found

filejavalog4jproperties

I have a Java Project that was added to the Java Build Path of a Web Project.

On the first Java project I added the Log4J JAR file to the Java Build Path and since this project was added to the Java Build Project of the Web Project, the JAR file was automatically added to the Web Project Java Build Path also.

On the Web Project I have a Web Service that instantiates a class of the Java Project. That class has a simple Logger, and it works correctly.

Now, I am trying to create a properties file named log4j.properties to configure the Logger, Appender and LayoutPattern.

Whenever I try to call a method of the instantiaded class I get this error on the console:

log4j:ERROR Could not read configuration file [log4j.properties].

What am I doing wrong?

Here's the log4j properties file:

log4j.rootLogger=DEBUG, CA

log4j.appender.CA=org.apache.log4j.ConsoleAppender 
log4j.appender.CA.layout=org.apache.log4j.PatternLayout 
log4j.appender.CA.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

Sorry but it was a false alarm…

Like I said, the project where the class that instantiates the logger resides is added as a dependency o a main project where the web services are defined.

As a result that project is published on a JAR file and with the suposed solution I mentioned:

PropertyConfigurator.configure(getClass().getProtectionDomain().getCodeSource().getLocation().getPath() + "log4j.properties");

I get a path like:

C:/project_path.jar/log4j.properties.

Obviously the propertied files still isn't found…

Sory… Still working on a solution

Best Answer

If using log4j 2.x, you need to have a file called log4j2.xml.

log4j.properties won't do it.