How to configure log4j in a java project that does not have the src folder?

Asked

Viewed 215 times

0

I have a Java project that does not have the src(8z !) folder and I need to use log4j, I created the log4j.properties file and inserted it into the main package (com.meuproj.main), but the log file is not created when I run the application executable.

I’m using log4j 1.2.17

1 answer

0

the file is loaded by log4j as a resource, so it is searched in the subdirectories that are in the classpath. In Eclipse and build tools like Maven and Gradle, the source folder (usually src) is added to the classpath, which is why the file is found by log4j. So the answer is: put the Loj4j configuration file in any folder of your project that is part of CLASSPATH.

http://svn.apache.org/viewvc/logging/log4j/trunk/src/main/java/org/apache/log4j/LogManager.java?view=markup#l110

https://logging.apache.org/log4j/1.2/manual.html#Default_Initialization_Procedure

Browser other questions tagged

You are not signed in. Login or sign up in order to post.