如果 Tomcat 下部署多个项目的时候 logPath 会出现项目之间串用问题,所以启用 customLogPath 名字

This commit is contained in:
thinkgem
2021-04-15 18:57:36 +08:00
parent 3a770f2818
commit c9dd006597

View File

@@ -218,21 +218,24 @@ public class PropertiesUtils {
*/ */
private static Logger initLogger(){ private static Logger initLogger(){
String logPath = null; String logPath = null;
try { if (StringUtils.isNotBlank(System.getProperty("customLogPath"))){
// 获取当前classes目录 // 如果 Tomcat 下部署多个项目的时候 logPath 会出现项目之间串用问题,所以启用 customLogPath 名字
logPath = ResourceUtils.getResource("/").getFile().getPath(); logPath = System.getProperty("customLogPath");
} catch (Exception e) { }else{
// 取不到,取当前工作路径 try {
logPath = System.getProperty("user.dir"); // 获取当前classes目录
} logPath = ResourceUtils.getResource("/").getFile().getPath();
// 取当前日志路径下有classes目录则使用classes目录 } catch (Exception e) {
String classesLogPath = FileUtils.path(logPath + "/WEB-INF/classes"); // 取不到,取当前工作路径
if (new File(classesLogPath).exists()){ logPath = System.getProperty("user.dir");
logPath = classesLogPath; }
} // 取当前日志路径下有classes目录则使用classes目录
if (StringUtils.isBlank(System.getProperty("logPath"))){ String classesLogPath = FileUtils.path(logPath + "/WEB-INF/classes");
System.setProperty("logPath", FileUtils.path(logPath)); if (new File(classesLogPath).exists()){
logPath = classesLogPath;
}
} }
System.setProperty("logPath", FileUtils.path(logPath));
return LoggerFactory.getLogger(PropertiesUtils.class); return LoggerFactory.getLogger(PropertiesUtils.class);
} }