0
votes

I'm trying to configure my log4j framework by providing a log4j.properties file in my classpath of my plugin, but log4j keeps complaining that it cannot find the file ... Here is a screenshot of my project structure and where I put my log4j.properties file: enter image description here

I put the file everywhere I could think of, as shown in the image above, but it still keeps complaining that it cannot find the file. Here is the console output after adding -Dlog4j.debug=true -Dlog4j.configuration=log4j.properties to my VM arguments:

log4j: Trying to find [log4j.properties] using context classloader org.eclipse.core.runtime.internal.adaptor.ContextFinder@6162abf8.
log4j: Trying to find [log4j.properties] using org.eclipse.osgi.internal.baseadaptor.DefaultClassLoader@4caeca49[org.apache.log4j:1.2.16(id=801)] class loader.
log4j: Trying to find [log4j.properties] using ClassLoader.getSystemResource().
log4j: Could not find resource: [log4j.properties].

I'm using eclipse Kepler Service Release 2 and log4j 1.2.15. The plugin is part of a RCP application which is called during the start-up phase of the application to initialize the logging framework. The logging itself works as expected, but I want to adapt a few settings to decrease the logging size. And yes I also added the file to the build-path to ensure that it is also available during execution. Any help or pointers would be appreciated.

Best regards,

Tom

1
there is no need to add any VM arguments, just confirm that it's at class-path. - Braj
@user3218114 I just added them for debugging purposes ... It also doesn't work when I remove the VM arguments - tzwickl
Try adjusting the navigator/project view to make sure the target directory is shown you probably want to make sure the properties file is getting copied into that location - LhasaDad
btw. think you had some information leakage in the first line, right side of your screen cap that you might not want? - LhasaDad
@lhasadad Yes, thanks for the hint :) - tzwickl

1 Answers

0
votes

OK I found the solution by myself :) I resolved the problem by explicitly configuring log4j by using the following code:

URL url = getClass().getResource("log4j.properties");        
PropertyConfigurator.configure(url);

Just place your log4j.properties in the package where you call this code and it should work ;) You only have to call this code once when you initialize the log4j framework.

Best regards, Tom