Commit b6776e88 authored by Spencer Chang's avatar Spencer Chang

[refactor] 类名修改、格式化代码

parent eb7fefaa
......@@ -20,7 +20,7 @@
### 查询结果直接导出Excel。
### update & delete 语句默认会根据where条件先备份源数据。
### 每次执行的语句都会存储到数据库中(不管是否执行成功),并记录当前执行人ip、用户等信息。
### 日志下载7天内的leaf.log
### 日志下载7天内的leaf.log;新增下载当天集群环境所有的日志
## 支持版本
### Leaf4.1 & Leaf4.2
......
......@@ -7,6 +7,6 @@
### 2、配置文件 spring/applicationContext-redis.xml 添加:
```xml
<bean id="sysClusterLogFileProviderImpl" class="com.hand.hls.dp.service.impl.SysClusterLogFileProviderImpl"/>
<bean id="sysClusterLogFileProviderImpl" class="com.hand.hls.dp.service.impl.SysClusterLogFileSubscriber"/>
```
......@@ -25,11 +25,16 @@ import java.util.zip.ZipOutputStream;
* @date 2020/9/3 14:32
* @since 1.0
*/
@TopicMonitor(channel = SysClusterLogFileProviderImpl.LOGFILE_DOWNLOAD)
public class SysClusterLogFileProviderImpl implements IMessageConsumer<String>, InitializingBean {
private Logger logger = LoggerFactory.getLogger(SysClusterLogFileProviderImpl.class);
@TopicMonitor(channel = SysClusterLogFileSubscriber.LOGFILE_DOWNLOAD)
public class SysClusterLogFileSubscriber implements IMessageConsumer<String>, InitializingBean {
private final Logger logger = LoggerFactory.getLogger(SysClusterLogFileSubscriber.class);
public static final String LOGFILE_DOWNLOAD = "topic:logfile:download";
public static final String LOGFILE_KEY = "leaf:logs:zip";
/**
* @see <a href="https://redis.io/topics/data-types">Data types</a>
* <p>The max length of a list is 2<sup>32</sup> - 1 elements (4294967295, more than 4 billion of elements per list).</p>
*/
private static final long MAX_LENGTH = 4294967295L;
@Value("${log-path}")
private String logPath;
......
......@@ -45,20 +45,23 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
/**
* 通知集群服务器当天日志暂存到redis
*
* @param requestContext 请求上下文
* @param request http请求
* @param response http响应
* @param request http请求
* @param response http响应
* @throws Exception 异常
*/
@Override
public void collectLog(IRequest requestContext, HttpServletRequest request, HttpServletResponse response) throws Exception {
messagePublisher.publish(SysClusterLogFileProviderImpl.LOGFILE_DOWNLOAD, "download logfile");
messagePublisher.publish(SysClusterLogFileSubscriber.LOGFILE_DOWNLOAD, "download logfile");
}
/**
* 下载集群服务器上当天日志
*
* @param requestContext 请求上下文
* @param request http请求
* @param response http响应
* @param request http请求
* @param response http响应
* @throws Exception 异常
*/
@Override
......@@ -72,10 +75,10 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
response.setHeader("Expires", "0");
response.setHeader("Content-Disposition", "attachment;filename=" + new String(zipFileName.getBytes(), StandardCharsets.ISO_8859_1));
response.setContentType("application/x-msdownload;");
List<String> zipFileList = redisTemplate.opsForList().range(SysClusterLogFileProviderImpl.LOGFILE_KEY, 0 , -1);
List<String> zipFileList = redisTemplate.opsForList().range(SysClusterLogFileSubscriber.LOGFILE_KEY, 0, -1);
// 清空
while (redisTemplate.opsForList().size(SysClusterLogFileProviderImpl.LOGFILE_KEY) > 0){
redisTemplate.opsForList().leftPop(SysClusterLogFileProviderImpl.LOGFILE_KEY);
while (redisTemplate.opsForList().size(SysClusterLogFileSubscriber.LOGFILE_KEY) > 0) {
redisTemplate.opsForList().leftPop(SysClusterLogFileSubscriber.LOGFILE_KEY);
}
int size = zipFileList.size();
if (size >= 1) {
......@@ -112,36 +115,37 @@ public class SysDpDownloadLogServiceImpl implements SysDpDownloadLogService {
/**
* 下载当前请求的服务器上7天日志
*
* @param requestContext 请求上下文
* @param request http请求
* @param response http响应
* @param request http请求
* @param response http响应
* @throws Exception 异常
*/
@Override
public void download(IRequest requestContext, HttpServletRequest request, HttpServletResponse response) throws Exception {
String zipFileName = DateUtil.format(new Date(),"yyyyMMddHHmmss") + "_logs.zip";
String zipFileName = DateUtil.format(new Date(), "yyyyMMddHHmmss") + "_logs.zip";
response.reset();
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache,must-revalidate");
response.setHeader("Expires","0");
response.setHeader("Content-Disposition","attachment;filename=" + new String(zipFileName.getBytes(), StandardCharsets.ISO_8859_1));
response.setHeader("Pragma", "No-cache");
response.setHeader("Cache-Control", "no-cache,must-revalidate");
response.setHeader("Expires", "0");
response.setHeader("Content-Disposition", "attachment;filename=" + new String(zipFileName.getBytes(), StandardCharsets.ISO_8859_1));
response.setContentType("application/x-msdownload;");
ByteArrayOutputStream byteOutPut = new ByteArrayOutputStream();
CheckedOutputStream cos = new CheckedOutputStream(byteOutPut,new CRC32());
CheckedOutputStream cos = new CheckedOutputStream(byteOutPut, new CRC32());
ZipOutputStream zos = new ZipOutputStream(cos);
// 下载7天内的日志
String[] downloadFiles = new String[7];
int length = downloadFiles.length;
// 当前日志
downloadFiles[0] = logPath + "leaf.log";
for (int i = 1; i <= length - 1;i++){
for (int i = 1; i <= length - 1; i++) {
LocalDate tmp = LocalDate.now().minusDays(i);
Date date = Date.from(tmp.atStartOfDay().atZone(ZoneId.systemDefault()).toInstant());
downloadFiles[i] = logPath + "leaf-" + DateUtil.format(date,"yyyy-MM-dd") + ".log";
downloadFiles[i] = logPath + "leaf-" + DateUtil.format(date, "yyyy-MM-dd") + ".log";
}
// 查找日志目录下所有文件
List<String> files = new ArrayList<>(31);
LogUtils.findFiles(new File(logPath),files);
LogUtils.findFiles(new File(logPath), files);
files.forEach(file -> {
for (String downloadFile : downloadFiles) {
if (file.equals(downloadFile)) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment