今天感觉Log4J2的配置文件要放在src文件下,感觉很别扭,没有和应用的其他配置文件放在一起,而且不能指定路径感觉也很不友好,网上搜了一下,大都是在启动的时候指定系统参数,指定配置文件的路径,想了下,既然是改变系统参数,通过代码应该也能实现,而且能够做成配置文件可配置路径化,岂不是更方便,自己摸索了一下,最终解决了这个问题,特分享一下。
首先,看了下Log4J2的官方介绍,如下:
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 JSON ConfigurationFactory will look for log4j2-test.json or log4j2-test.jsn in the classpath.
3.If no such file is found the XML ConfigurationFactory will look for log4j2-test.xml in the classpath.
4.If a test file cannot be located the JSON ConfigurationFactory will look for log4j2.json or log4j2.jsn on the classpath.
5.If a JSON file cannot be located the XML Configura