Добавлено автоматическое удаление логов, соответствующий параметр внесен в config.json
This commit is contained in:
parent
f68855f365
commit
f14990082a
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
Binary file not shown.
Binary file not shown.
|
@ -3,8 +3,11 @@ package org.dhaverdLogs;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.time.Duration;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.Period;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class DhaverdLogs {
|
public class DhaverdLogs {
|
||||||
public static final String osSeparator = System.getProperty("file.separator");
|
public static final String osSeparator = System.getProperty("file.separator");
|
||||||
|
@ -12,6 +15,38 @@ public class DhaverdLogs {
|
||||||
public static String fileName = "log.log";
|
public static String fileName = "log.log";
|
||||||
public static String logDir = "";
|
public static String logDir = "";
|
||||||
|
|
||||||
|
public static void logCleaner(boolean deleteBySevenDays) throws IOException {
|
||||||
|
File dir = new File(logDir);
|
||||||
|
if (!dir.isDirectory()){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File[] fileList = dir.listFiles();
|
||||||
|
assert fileList != null;
|
||||||
|
for (File file : fileList){
|
||||||
|
String fileName = file.getName();
|
||||||
|
if (!fileName.contains("gitignore")){
|
||||||
|
if (deleteBySevenDays){
|
||||||
|
String[] params = fileName.split("_");
|
||||||
|
String date = params[0];
|
||||||
|
date = date.replace('.', '-');
|
||||||
|
String time = params[1];
|
||||||
|
time = time.replace('-', ':');
|
||||||
|
String dateTime = date + "T" + time;
|
||||||
|
LocalDateTime now = LocalDateTime.now();
|
||||||
|
LocalDateTime logDateTime = LocalDateTime.parse(dateTime);
|
||||||
|
Duration duration = Duration.between(logDateTime, now);
|
||||||
|
long diff = Math.abs(duration.toDays());
|
||||||
|
if (diff > 7){
|
||||||
|
setLog("Log cleaner", "File " + file.getName() + " is deleted: " + file.delete(), true, false);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
setLog("Log cleaner", "File " + file.getName() + " is deleted: " + file.delete(), true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public static void setLogName(String name){
|
public static void setLogName(String name){
|
||||||
String time = getCurrentTime();
|
String time = getCurrentTime();
|
||||||
|
|
Loading…
Reference in New Issue