为什么Log4J2在log4j2-test.xml之后就停止了,不再继续寻找log4j2.xml?
Why does Log4J2 stop after log4j2-test.xml and not continue to look for log4j2.xml?
我有 2 个应用程序都在寻找 log4j2.xml。一个找到一个没有。
将此添加到 jvm 后:-Dlog4j.debug(使用 2.11.2 的所有内容)
第一个正确运行的应用程序扫描并找到文件:
第二个app在log4j2后停止扫描-test.xml
我
当我将 log4j2-test.xml 添加到第二个应用程序时,它会找到它并正常工作。显然存在差异(应用程序非常相似)但找不到。有任何想法吗?什么会导致 Log4j2 停止扫描 属性 文件?
由于 Log4j2 查找配置的顺序。
- 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.
- If no system property is set the properties ConfigurationFactory will look for log4j2-test.properties in the classpath.
- If no such file is found the YAML ConfigurationFactory will look for log4j2-test.yaml or log4j2-test.yml in the classpath.
- If no such file is found the JSON ConfigurationFactory will look for log4j2-test.json or log4j2-test.jsn in the classpath.
- If no such file is found the XML ConfigurationFactory will look for log4j2-test.xml in the classpath.
- If a test file cannot be located the properties ConfigurationFactory will look for log4j2.properties on the classpath.
- If a properties file cannot be located the YAML ConfigurationFactory will look for log4j2.yaml or log4j2.yml on the classpath.
- If a YAML file cannot be located the JSON ConfigurationFactory will look for log4j2.json or log4j2.jsn on the classpath.
- If a JSON file cannot be located the XML ConfigurationFactory will try to locate log4j2.xml on the classpath.
- If no configuration file could be located the DefaultConfiguration will be used. This will cause logging output to go to the console.
参考:https://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration
我有 2 个应用程序都在寻找 log4j2.xml。一个找到一个没有。
将此添加到 jvm 后:-Dlog4j.debug(使用 2.11.2 的所有内容)
第一个正确运行的应用程序扫描并找到文件:
第二个app在log4j2后停止扫描-test.xml
我
当我将 log4j2-test.xml 添加到第二个应用程序时,它会找到它并正常工作。显然存在差异(应用程序非常相似)但找不到。有任何想法吗?什么会导致 Log4j2 停止扫描 属性 文件?
由于 Log4j2 查找配置的顺序。
- 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.
- If no system property is set the properties ConfigurationFactory will look for log4j2-test.properties in the classpath.
- If no such file is found the YAML ConfigurationFactory will look for log4j2-test.yaml or log4j2-test.yml in the classpath.
- If no such file is found the JSON ConfigurationFactory will look for log4j2-test.json or log4j2-test.jsn in the classpath.
- If no such file is found the XML ConfigurationFactory will look for log4j2-test.xml in the classpath.
- If a test file cannot be located the properties ConfigurationFactory will look for log4j2.properties on the classpath.
- If a properties file cannot be located the YAML ConfigurationFactory will look for log4j2.yaml or log4j2.yml on the classpath.
- If a YAML file cannot be located the JSON ConfigurationFactory will look for log4j2.json or log4j2.jsn on the classpath.
- If a JSON file cannot be located the XML ConfigurationFactory will try to locate log4j2.xml on the classpath.
- If no configuration file could be located the DefaultConfiguration will be used. This will cause logging output to go to the console.
参考:https://logging.apache.org/log4j/2.x/manual/configuration.html#AutomaticConfiguration