Compare commits
2 Commits
release1.0
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
21b24c4d15 | ||
|
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.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.time.Duration;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.Period;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.List;
|
||||
|
||||
public class DhaverdLogs {
|
||||
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 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") && file.getName() != getLogFile().getName()){
|
||||
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){
|
||||
String time = getCurrentTime();
|
||||
|
|
Loading…
Reference in New Issue