日志路径生成优化;在磁盘根目录下BeetlUtil.getWebRoot()报错修正
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
<logger name="org.mybatis.spring.transaction" level="DEBUG" />
|
||||
<logger name="org.apache.catalina.webresources.Cache" level="ERROR" />
|
||||
<logger name="org.springframework.boot.context.embedded" level="INFO" />
|
||||
<logger name="org.springframework.boot.autoconfigure.logging.AutoConfigurationReportLoggingInitializer" level="INFO" />
|
||||
<logger name="com.atomikos.icatch.config.UserTransactionServiceImp" level="ERROR" />
|
||||
<logger name="com.atomikos.jdbc.AbstractDataSourceBean" level="ERROR" />
|
||||
|
||||
|
||||
@@ -12,5 +12,3 @@ spring:
|
||||
|
||||
main:
|
||||
banner-mode: "off"
|
||||
|
||||
debug: true
|
||||
@@ -2,7 +2,7 @@
|
||||
<configuration debug="false" scan="false">
|
||||
|
||||
<!-- Log file path -->
|
||||
<property name="log.path" value="${logPath:-..}/logs" />
|
||||
<property name="log.path" value="${logPath:-${java.io.tmpdir:-.}}/logs" />
|
||||
|
||||
<!-- Spring boot default -->
|
||||
<include resource="org/springframework/boot/logging/logback/defaults.xml" />
|
||||
|
||||
Reference in New Issue
Block a user