-1

I have 2 apps that are both looking for log4j2.xml. One finds it and one doesn't.

After adding this to the jvm: -Dlog4j.debug (using 2.11.2 of everything)

The first app that runs correctly scans and finds the file:

enter image description here

The second app stops scanning after log4j2-test.xml

I enter image description here

When I add log4j2-test.xml to the second app, it finds it and works correctly. Obviously there is a difference (the apps are VERY similar) but can't find it. Any ideas? What would cause Log4j2 to stop scanning for the property file?

markthegrea
  • 3,731
  • 7
  • 55
  • 78

1 Answers1

0

Because of the order used by Log4j2 to look for configuration.

  1. Log4j will inspect the "log4j.configurationFile" system property and, if set, will attempt to load the configuration using the ConfigurationFactory that matches the file extension.
  2. If no system property is set the properties ConfigurationFactory will look for log4j2-test.properties in the classpath.
  3. If no such file is found the YAML ConfigurationFactory will look for log4j2-test.yaml or log4j2-test.yml in the classpath.
  4. If no such file is found the JSON ConfigurationFactory will look for log4j2-test.json or log4j2-test.jsn in the classpath.
  5. If no such file is found the XML ConfigurationFactory will look for log4j2-test.xml in the classpath.
  6. If a test file cannot be located the properties ConfigurationFactory will look for log4j2.properties on the classpath.
  7. If a properties file cannot be located the YAML ConfigurationFactory will look for log4j2.yaml or log4j2.yml on the classpath.
  8. If a YAML file cannot be located the JSON ConfigurationFactory will look for log4j2.json or log4j2.jsn on the classpath.
  9. If a JSON file cannot be located the XML ConfigurationFactory will try to locate log4j2.xml on the classpath.
  10. If no configuration file could be located the DefaultConfiguration will be used. This will cause logging output to go to the console.

Reference: https://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration

sazzad
  • 5,740
  • 6
  • 25
  • 42
  • You are correct. I could not find the log4j2-test.xml anywhere, but it must be finding one somewhere. Thanks for the help! – markthegrea Jun 04 '19 at 17:50