From c9dd006597a8768475418f69a35d587cbc955cd0 Mon Sep 17 00:00:00 2001 From: thinkgem Date: Thu, 15 Apr 2021 18:57:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9C=20Tomcat=20=E4=B8=8B?= =?UTF-8?q?=E9=83=A8=E7=BD=B2=E5=A4=9A=E4=B8=AA=E9=A1=B9=E7=9B=AE=E7=9A=84?= =?UTF-8?q?=E6=97=B6=E5=80=99=20logPath=20=E4=BC=9A=E5=87=BA=E7=8E=B0?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E4=B9=8B=E9=97=B4=E4=B8=B2=E7=94=A8=E9=97=AE?= =?UTF-8?q?=E9=A2=98=EF=BC=8C=E6=89=80=E4=BB=A5=E5=90=AF=E7=94=A8=20custom?= =?UTF-8?q?LogPath=20=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeesite/common/io/PropertiesUtils.java | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/common/src/main/java/com/jeesite/common/io/PropertiesUtils.java b/common/src/main/java/com/jeesite/common/io/PropertiesUtils.java index 2f77ef0f..9dbbfe88 100644 --- a/common/src/main/java/com/jeesite/common/io/PropertiesUtils.java +++ b/common/src/main/java/com/jeesite/common/io/PropertiesUtils.java @@ -218,21 +218,24 @@ public class PropertiesUtils { */ private static Logger initLogger(){ String logPath = null; - try { - // 获取当前classes目录 - logPath = ResourceUtils.getResource("/").getFile().getPath(); - } catch (Exception e) { - // 取不到,取当前工作路径 - logPath = System.getProperty("user.dir"); - } - // 取当前日志路径下有classes目录,则使用classes目录 - String classesLogPath = FileUtils.path(logPath + "/WEB-INF/classes"); - if (new File(classesLogPath).exists()){ - logPath = classesLogPath; - } - if (StringUtils.isBlank(System.getProperty("logPath"))){ - System.setProperty("logPath", FileUtils.path(logPath)); + if (StringUtils.isNotBlank(System.getProperty("customLogPath"))){ + // 如果 Tomcat 下部署多个项目的时候 logPath 会出现项目之间串用问题,所以启用 customLogPath 名字 + logPath = System.getProperty("customLogPath"); + }else{ + try { + // 获取当前classes目录 + logPath = ResourceUtils.getResource("/").getFile().getPath(); + } catch (Exception e) { + // 取不到,取当前工作路径 + logPath = System.getProperty("user.dir"); + } + // 取当前日志路径下有classes目录,则使用classes目录 + String classesLogPath = FileUtils.path(logPath + "/WEB-INF/classes"); + if (new File(classesLogPath).exists()){ + logPath = classesLogPath; + } } + System.setProperty("logPath", FileUtils.path(logPath)); return LoggerFactory.getLogger(PropertiesUtils.class); }