日志清除
This commit is contained in:
@@ -36,8 +36,4 @@ public interface LogRepository extends JpaRepository<Log,Long>, JpaSpecification
|
|||||||
@Modifying
|
@Modifying
|
||||||
@Query(value = "delete from sys_log where log_type = ?1", nativeQuery = true)
|
@Query(value = "delete from sys_log where log_type = ?1", nativeQuery = true)
|
||||||
void deleteByLogType(String logType);
|
void deleteByLogType(String logType);
|
||||||
|
|
||||||
@Modifying
|
|
||||||
@Query(value = "delete from sys_log where log_type = ?1 and DATEDIFF(NOW(),create_time) >= 15", nativeQuery = true)
|
|
||||||
void delAfterDay(String logType);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,14 +79,4 @@ public interface LogService {
|
|||||||
* 删除所有INFO日志
|
* 删除所有INFO日志
|
||||||
*/
|
*/
|
||||||
void delAllByInfo();
|
void delAllByInfo();
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除15天之前的错误日志
|
|
||||||
*/
|
|
||||||
void delAfterDay15ByError();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 删除15天之前的INFO日志
|
|
||||||
*/
|
|
||||||
void delAfterDay15ByInfo();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,16 +155,4 @@ public class LogServiceImpl implements LogService {
|
|||||||
public void delAllByInfo() {
|
public void delAllByInfo() {
|
||||||
logRepository.deleteByLogType("INFO");
|
logRepository.deleteByLogType("INFO");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void delAfterDay15ByError() {
|
|
||||||
logRepository.delAfterDay("ERROR");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
@Transactional(rollbackFor = Exception.class)
|
|
||||||
public void delAfterDay15ByInfo() {
|
|
||||||
logRepository.delAfterDay("INFO");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ package org.nl.wms.autotask;
|
|||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.nl.modules.logging.service.LogService;
|
import org.nl.modules.system.service.ParamService;
|
||||||
|
import org.nl.modules.wql.core.bean.WQLObject;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,14 +13,14 @@ import org.springframework.stereotype.Component;
|
|||||||
@Component
|
@Component
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class CleanLog {
|
public class CleanLog {
|
||||||
private final LogService logService;
|
private final ParamService paramService;
|
||||||
|
|
||||||
public void run(){
|
public void run(){
|
||||||
// 删除所有异常日志
|
//delete from sys_log where DATE(create_time) <= DATE(DATE_SUB(NOW(),INTERVAL 30 day)) limit 10;
|
||||||
logService.delAfterDay15ByError();
|
WQLObject logTab = WQLObject.getWQLObject("sys_log");
|
||||||
// 删除所有操作日志
|
int days = Integer.parseInt(paramService.findByCode("log_day").getValue());
|
||||||
logService.delAfterDay15ByInfo();
|
logTab.delete("DATE(create_time) <= DATE(DATE_SUB(NOW(),INTERVAL " + days + " day))");
|
||||||
log.info("删除所有异常/操作日志 执行成功");
|
log.info("自动清理日志执行成功...!");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user