Compare commits
No commits in common. "1.0" and "main" have entirely different histories.
|
@ -1,6 +1,5 @@
|
|||
package net.limework.automaticlogdeleter;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
|
@ -38,16 +37,27 @@ public class AutomaticLogDeleter extends JavaPlugin {
|
|||
//maximum file age allowed
|
||||
|
||||
long maxOldMillis = config.getLong("delete-logs-older-than-seconds") * 1000;
|
||||
String fileName;
|
||||
|
||||
for (File file : files) {
|
||||
if (file.isFile()) {
|
||||
if ((System.currentTimeMillis() - file.lastModified()) > maxOldMillis) {
|
||||
fileName = file.getName();
|
||||
|
||||
if (!file.delete()) {
|
||||
Bukkit.getLogger().log(Level.WARNING, "[AutomaticLogDeleter] Failed to delete server log file! Are you sure the file permissions are correct?");
|
||||
} else {
|
||||
Bukkit.getLogger().log(Level.INFO, "[AutomaticLogDeleter] Deleted log file " + file.getName());
|
||||
}
|
||||
//if file is not a log file
|
||||
//using contains to make it more likely to catch different types of logging systems
|
||||
if (!fileName.contains(".log") && !fileName.contains("log.")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
//if file is older than configured time
|
||||
if ((System.currentTimeMillis() - file.lastModified()) < maxOldMillis) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!file.delete()) {
|
||||
getLogger().log(Level.WARNING, "[AutomaticLogDeleter] Failed to delete server log file! Are you sure the file permissions are correct?");
|
||||
} else {
|
||||
getLogger().log(Level.INFO, "[AutomaticLogDeleter] Deleted log file " + fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,3 +11,9 @@ delete-logs-older-than-seconds: 86400
|
|||
#default value: false
|
||||
|
||||
also-delete-logs-on-shutdown: false
|
||||
|
||||
#list of directories to check for logs
|
||||
#note it will only delete files that contain ".log" in their name for safety reasons
|
||||
#not yet implemented
|
||||
check-directories-for-logs:
|
||||
- "logs"
|
||||
|
|
Loading…
Reference in New Issue