From 0fc3693b035af8be5e07af1e86584af394762d75 Mon Sep 17 00:00:00 2001 From: thinkgem Date: Sat, 5 May 2018 19:32:09 +0800 Subject: [PATCH] =?UTF-8?q?=E6=97=A5=E5=BF=97=E8=B7=AF=E5=BE=84=E7=94=9F?= =?UTF-8?q?=E6=88=90=E4=BC=98=E5=8C=96=EF=BC=9B=E5=9C=A8=E7=A3=81=E7=9B=98?= =?UTF-8?q?=E6=A0=B9=E7=9B=AE=E5=BD=95=E4=B8=8BBeetlUtil.getWebRoot()?= =?UTF-8?q?=E6=8A=A5=E9=94=99=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../jeesite/common/io/PropertiesUtils.java | 25 ++++++++++++++++++- .../src/main/resources/config/logger-core.xml | 1 + web/src/main/resources/config/application.yml | 2 -- web/src/main/resources/logback.xml | 2 +- 4 files changed, 26 insertions(+), 4 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 fa460594..1aaeef2b 100644 --- a/common/src/main/java/com/jeesite/common/io/PropertiesUtils.java +++ b/common/src/main/java/com/jeesite/common/io/PropertiesUtils.java @@ -3,6 +3,7 @@ */ package com.jeesite.common.io; +import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.util.Map; @@ -15,6 +16,7 @@ import org.apache.commons.io.IOUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.config.YamlPropertiesFactoryBean; +import org.springframework.core.io.DefaultResourceLoader; import org.springframework.core.io.Resource; import com.jeesite.common.collect.SetUtils; @@ -35,7 +37,7 @@ public class PropertiesUtils { "classpath:config/application.yml", "classpath:application.yml"}; - private static Logger logger = LoggerFactory.getLogger(PropertiesUtils.class); + private static Logger logger = PropertiesUtils.initLogger(); private final Properties properties = new Properties(); @@ -151,4 +153,25 @@ public class PropertiesUtils { return value != null ? value : defaultValue; } + /** + * 初始化日志路径 + */ + private static Logger initLogger(){ + String logPath = null; + try { + // 获取当前classes目录 + logPath = new DefaultResourceLoader().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); + } + } diff --git a/modules/core/src/main/resources/config/logger-core.xml b/modules/core/src/main/resources/config/logger-core.xml index 4bbcd61c..2d46a2df 100644 --- a/modules/core/src/main/resources/config/logger-core.xml +++ b/modules/core/src/main/resources/config/logger-core.xml @@ -6,6 +6,7 @@ + diff --git a/web/src/main/resources/config/application.yml b/web/src/main/resources/config/application.yml index 049ee62a..8c87cd89 100644 --- a/web/src/main/resources/config/application.yml +++ b/web/src/main/resources/config/application.yml @@ -12,5 +12,3 @@ spring: main: banner-mode: "off" - -debug: true \ No newline at end of file diff --git a/web/src/main/resources/logback.xml b/web/src/main/resources/logback.xml index 2c949195..dace0c59 100644 --- a/web/src/main/resources/logback.xml +++ b/web/src/main/resources/logback.xml @@ -2,7 +2,7 @@ - +