We are bundling Log4j 1.2.15 with our plain Swing application and load our own properties file from the file system at startup:
import org.apache.log4j.*;
...
System.setProperty("log4j.defaultInitOverride", "true");
...
File log4jPropertiesFile = ...
PropertyConfigurator.configure(log4jPropertiesFile.getAbsolutePath());
...
In logs we are getting from customers the output does not look like we have defined in the properties file and we are sure that not more than a very small minority edited the file themself.
Could it be that Log4j somehow overrides our settings if there is another configuration file somewhere present on the user’s machine available? How we can prevent using that?
There’s a whole paragraph in the docs detailing how Log4j initializes itself:
This is, admittedly, confusing as hell to understand. Basically, the simplest thing you can do is put
log4j.propertieson the classpath of your app, and it will be found. Everything else is… finesse. Personally, I sometimes explicitly call theBasicConfiguratorclass in mymain, sometimes configuring (hard coded) some of the stuff that might otherwise appear in a file… whatever my circumstances call for. You can initialize log4j completely programmatically, and that would kind of make the question of the configuration file moot. Though it would also make your configuration completely less flexible.