Where to place log4j.xml

前端 未结 6 740
滥情空心
滥情空心 2020-11-30 02:37

How can we specify were log4j has to look at when trying to find its xml configuration file ?

It seems that by default, log4j looks into the root of a class folder,

6条回答
  •  爱一瞬间的悲伤
    2020-11-30 03:04

    May be this is very old question, but for me the answer was here https://logging.apache.org/log4j/2.x/manual/configuration.html

    As per above link, Apache log search in classpath for the log4j2.xml files in a specific order as below

    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. If no such file is found the XML ConfigurationFactory will look for log4j2-test.xml in the classpath.
    5. If a test file cannot be located the properties ConfigurationFactory will look for log4j2.properties on the classpath.
    6. If a properties file cannot be located the YAML ConfigurationFactory will look for log4j2.yaml or log4j2.yml on the classpath.
    7. If a YAML file cannot be located the JSON ConfigurationFactory will look for log4j2.json or log4j2.jsn on the classpath.
    8. If a JSON file cannot be located the XML ConfigurationFactory will try to locate log4j2.xml on the classpath.
    9. If no configuration file could be located the DefaultConfiguration will be used. This will cause logging output to go to the console.

提交回复
热议问题