6 Commits
0.0.1 ... 1.1

Author SHA1 Message Date
Govindas
e443004fd7 <> symbols are confusing 2021-06-15 10:04:57 +03:00
Govindas
89f6919d0b Make log file detection even more lenient 2021-06-14 10:41:19 +03:00
Govindas
46b91266d5 more lenient log file detection 2021-06-13 12:30:35 +03:00
Govindas
13cdc1046c Merge branch 'main' of https://github.com/Limework/AutomaticLogDeleter into main 2021-06-13 12:12:09 +03:00
Govindas
a7c85ad06d Only delete log files and nothing else 2021-06-13 12:12:06 +03:00
Govindas
444f77d902 Update README.md 2021-06-12 12:15:34 +00:00
3 changed files with 36 additions and 6 deletions

View File

@@ -1,2 +1,15 @@
# AutomaticLogDeleter # AutomaticLogDeleter
Deletes old server logs automatically Deletes old server logs automatically
# Config
```yaml
#AutomaticLogDeleter plugin config
#lines that start with a hashtag are comments
#delete logs older than 24 hours by default
#you can set it to -1 to simply delete all logs
#default value: 86400
delete-logs-older-than-seconds: 86400
#by default old logs are deleted only on startup
#default value: false
also-delete-logs-on-shutdown: false
```

View File

@@ -38,16 +38,27 @@ public class AutomaticLogDeleter extends JavaPlugin {
//maximum file age allowed //maximum file age allowed
long maxOldMillis = config.getLong("delete-logs-older-than-seconds") * 1000; long maxOldMillis = config.getLong("delete-logs-older-than-seconds") * 1000;
String fileName;
for (File file : files) { for (File file : files) {
if (file.isFile()) { if (file.isFile()) {
if ((System.currentTimeMillis() - file.lastModified()) > maxOldMillis) { fileName = 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()) { if (!file.delete()) {
Bukkit.getLogger().log(Level.WARNING, "[AutomaticLogDeleter] Failed to delete server log file! Are you sure the file permissions are correct?"); getLogger().log(Level.WARNING, "[AutomaticLogDeleter] Failed to delete server log file! Are you sure the file permissions are correct?");
} else { } else {
Bukkit.getLogger().log(Level.INFO, "[AutomaticLogDeleter] Deleted log file " + file.getName()); getLogger().log(Level.INFO, "[AutomaticLogDeleter] Deleted log file " + fileName);
}
} }
} }
} }

View File

@@ -11,3 +11,9 @@ delete-logs-older-than-seconds: 86400
#default value: false #default value: false
also-delete-logs-on-shutdown: 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"