mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-02 03:48:05 +08:00
支持清理太久的控制台日志文件
This commit is contained in:
parent
dd3e2237c7
commit
045371f149
11
CHANGELOG.md
11
CHANGELOG.md
@ -1,5 +1,14 @@
|
||||
# 版本日志
|
||||
|
||||
## 2.3.2
|
||||
|
||||
### 新增功能
|
||||
1. 控制台日志支持配置报错天数
|
||||
|
||||
### 解决BUG
|
||||
|
||||
-----------------------------------------------------------
|
||||
|
||||
## 2.3.1
|
||||
|
||||
#### 新增功能
|
||||
@ -24,7 +33,7 @@
|
||||
5. 用户授权项目权限不足问题
|
||||
|
||||
#### 升级注意事项
|
||||
1. 由2.2 升级到 2.3.x 需要手动删除Jpom数据目录中的`data/user.json` 文件、所有用户账户信息将失效需要重新添加
|
||||
1. 由2.2及以下升级到 2.3.x 需要手动删除Jpom数据目录中的`data/user.json` 文件、所有用户账户信息将失效需要重新添加
|
||||
|
||||
-----------------------------------------------------------
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -12,7 +12,7 @@
|
||||
<artifactId>jpom</artifactId>
|
||||
<name>Jpom Java项目在线管理</name>
|
||||
<inceptionYear>2017</inceptionYear>
|
||||
<version>2.3.1</version>
|
||||
<version>2.3.2</version>
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
|
@ -79,6 +79,11 @@ public class ExtConfigBean {
|
||||
*/
|
||||
@Value("${log.autoBackSize:50MB}")
|
||||
public String autoBackSize;
|
||||
/**
|
||||
* 控制台日志保存时长单位天
|
||||
*/
|
||||
@Value("${log.saveDays:7}")
|
||||
private int logSaveDays;
|
||||
/**
|
||||
* 项目运行存储路径
|
||||
*/
|
||||
@ -112,6 +117,18 @@ public class ExtConfigBean {
|
||||
return path;
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置错误或者没有,默认是7天
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public int getLogSaveDays() {
|
||||
if (logSaveDays <= 0) {
|
||||
return 7;
|
||||
}
|
||||
return logSaveDays;
|
||||
}
|
||||
|
||||
/**
|
||||
* 单例
|
||||
*
|
||||
|
@ -1,6 +1,9 @@
|
||||
package cn.keepbx.jpom.system.init;
|
||||
|
||||
import ch.qos.logback.core.util.FileSize;
|
||||
import cn.hutool.core.date.DateTime;
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.cron.CronUtil;
|
||||
import cn.hutool.cron.Scheduler;
|
||||
@ -37,8 +40,9 @@ public class AutoBackLog {
|
||||
projectInfoService = SpringUtil.getBean(ProjectInfoService.class);
|
||||
}
|
||||
// 获取cron 表达式
|
||||
String cron = StrUtil.emptyToDefault(ExtConfigBean.getInstance().autoBackConsoleCron, "");
|
||||
String cron = StrUtil.emptyToDefault(ExtConfigBean.getInstance().autoBackConsoleCron, "none");
|
||||
if ("none".equalsIgnoreCase(cron.trim())) {
|
||||
DefaultSystemLog.LOG().info("没有配置自动备份控制台日志表达式");
|
||||
return;
|
||||
}
|
||||
String size = StrUtil.emptyToDefault(ExtConfigBean.getInstance().autoBackSize, "50MB");
|
||||
@ -63,6 +67,16 @@ public class AutoBackLog {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
// 清理过期的文件
|
||||
File logFile = projectInfoModel.getLogBack();
|
||||
DateTime nowTime = DateTime.now();
|
||||
List<File> files = FileUtil.loopFiles(logFile, pathname -> {
|
||||
DateTime dateTime = DateUtil.date(pathname.lastModified());
|
||||
long days = DateUtil.betweenDay(dateTime, nowTime, false);
|
||||
long saveDays = ExtConfigBean.getInstance().getLogSaveDays();
|
||||
return days > saveDays;
|
||||
});
|
||||
files.forEach(FileUtil::del);
|
||||
});
|
||||
} catch (Exception e) {
|
||||
DefaultSystemLog.ERROR().error("定时备份日志失败", e);
|
||||
|
@ -17,4 +17,6 @@ log:
|
||||
# 自动备份控制台日志,防止日志文件过大,目前暂只支持linux 不停服备份
|
||||
autoBackConsoleCron: 0 0/10 * * * ?
|
||||
# 当文件多大时自动备份
|
||||
autoBackSize: 50MB
|
||||
autoBackSize: 50MB
|
||||
# 保存天数 配置错误或者没有,默认是7天
|
||||
saveDays: 7
|
@ -64,7 +64,7 @@
|
||||
<!-- layui-elem-quote -->
|
||||
#if($logSize)
|
||||
<button id="export" class="layui-btn layui-btn-sm">导出日志</button>
|
||||
<button id="resetLog" class="layui-btn layui-btn-sm">重置(<span id="logSize">$logSize</span>)</button>
|
||||
<button id="resetLog" class="layui-btn layui-btn-sm">重置日志(<span id="logSize">$logSize</span>)</button>
|
||||
#end
|
||||
#if($logBack)
|
||||
<button id="logBack" class="layui-btn layui-btn-sm">备份列表</button>
|
||||
@ -201,6 +201,11 @@
|
||||
|
||||
function scrollToBotomm() {
|
||||
var h = showLogDom[0].scrollHeight;
|
||||
if (window.screen.height * 2 < h) {
|
||||
showLogDom.html("已清空屏幕缓存");
|
||||
showLogDom.scrollTop(0);
|
||||
return;
|
||||
}
|
||||
showLogDom.scrollTop(h);
|
||||
}
|
||||
|
||||
|
@ -199,9 +199,10 @@
|
||||
if (val === "") {
|
||||
val = "请填写";
|
||||
$("#tipMsgDiv").hide();
|
||||
} else {
|
||||
checngeLib();
|
||||
}
|
||||
$("#projectEnd").text(val);
|
||||
checngeLib();
|
||||
});
|
||||
|
||||
function checngeLib() {
|
||||
|
Loading…
Reference in New Issue
Block a user