user893664
user893664

Reputation: 319

where to put log4j.properties- for use in java desktop app

I am trying to use log4j logging framework in a java desktop application.

When I run the code I am getting a message

log4j: log4j:WARN No appenders could be found for logger 

I googled for the above error and found that it occurs when the log4j.properties file is not found by the app.

I am creating the desktop app using Eclipse. Currently log4j.properties is within the same folder that contains the source (in 'src' folder). Where should I put this file to make it work properly?

Upvotes: 2

Views: 5592

Answers (2)

FrVaBe
FrVaBe

Reputation: 49341

log4j will use a Default Initialization Procedure to find your configuration file. The documentation notes:

The preferred way to specify the default initialization file is through the log4j.configuration system property

If this property is not set - log4j will look at the classpath. In your case you have to place the file in the src directory (assumed that the content will be put in the classes path while you build the system). If you use maven place the file to the src/main/resources directory.

As you placed your file to the src directory check, that the file get transferred to the top level directory of your compiled classes.

Upvotes: 3

Naved
Naved

Reputation: 4128

Keep the properties file in the classes folder i.e. the folder that contains the classes (specially the main class).
Another reason for getting this error may be the wrong appenders or an appender without setting.

Upvotes: 0

Related Questions