mirror of
https://gitee.com/wangkang/udf.git
synced 2026-10-28 16:33:43 +00:00
日志文件删除机制
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
package org.itkk.udf.core;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.commons.lang3.ArrayUtils;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* CleanLogFile
|
||||
*/
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CleanLogFile {
|
||||
|
||||
/**
|
||||
* logFile
|
||||
*/
|
||||
@Value("${logging.file}")
|
||||
private String logFile;
|
||||
|
||||
/**
|
||||
* 清理日志文件
|
||||
*/
|
||||
@Scheduled(cron = "0 0 1 * * ?")
|
||||
public void cleanLog() {
|
||||
log.info("cleanLog begin : {}", logFile);
|
||||
File file = new File(logFile);
|
||||
if (file.exists()) {
|
||||
File dir = file.getParentFile();
|
||||
if (dir.exists() && dir.isDirectory()) {
|
||||
File[] files = dir.listFiles();
|
||||
if (ArrayUtils.isNotEmpty(files)) {
|
||||
Arrays.stream(files).filter(f -> !logFile.equals(f.getAbsolutePath())).forEach(f -> {
|
||||
try {
|
||||
log.info("cleanLog : {}", f.getAbsolutePath());
|
||||
Files.delete(f.toPath());
|
||||
} catch (IOException e) {
|
||||
log.warn("msg:", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("cleanLog end : {}", logFile);
|
||||
}
|
||||
|
||||
}
|
||||
+2
-2
@@ -42,9 +42,9 @@ public class DownLoadProcessAspect {
|
||||
public static final String DOWNLOAD_CACHE_PREFIX = "DOWNLOAD_CACHE:";
|
||||
|
||||
/**
|
||||
* DOWNLOAD_WAITING_CACHE_EXPIRATION(待执行,执行中,缓存过期时间为1小时)
|
||||
* DOWNLOAD_WAITING_CACHE_EXPIRATION(待执行,执行中,缓存过期时间为30分钟)
|
||||
*/
|
||||
public static final long DOWNLOAD_WAITING_CACHE_EXPIRATION = 60L * 1L;
|
||||
public static final long DOWNLOAD_WAITING_CACHE_EXPIRATION = 30L;
|
||||
|
||||
/**
|
||||
* DOWNLOAD_CACHE_EXPIRATION(执行完成,执行错误,缓存过期时间为1分钟)
|
||||
|
||||
Reference in New Issue
Block a user