前段时间日志输出一直好好的,可是突然有一天部署了之后就不再输出日志了。后来发现原因是在 mycat/server/1.5.1/server-1.5.1.jar ( jar:file:/C:/Users/Administrator/.m2/repository/mycat/server/1.5.1/server-1.5.1.jar!/log4j.xml)
这个包里存在log4j.xml配置文件,log4j加载配置文件顺序是先找log4j.xml,如果没有,再找log4j.properties文件,就是因为server-1.5.1.jar已经存在log4j.xml 所以不再去加载我们项目的配置文件。最后去掉这个无用的依赖包 server-1.5.1.jar 就可以了
Log4j源码
// if the user has not specified the log4j.configuration
// property, we search first for the file "log4j.xml" and then
// "log4j.properties"
if(configurationOptionStr == null) {
url = Loader.getResource(DEFAULT_XML_CONFIGURATION_FILE);
if(url == null) {
url = Loader.getResource(DEFAULT_CONFIGURATION_FILE);
}
} else {
try {
url = new URL(configurationOptionStr);
} catch (MalformedURLException ex) {
// so, resource is not a URL:
// attempt to get the resource from the class path
url = Loader.getResource(configurationOptionStr);
}
}