From c0c7011643a6ffa7c549ad4eff662309644b244c Mon Sep 17 00:00:00 2001 From: Cow Date: Sun, 4 Jul 2021 11:33:31 +0200 Subject: Added separate max file size for latest.log --- src/main/java/de/cowtipper/cowlection/config/MooConfig.java | 13 +++++++++++++ src/main/java/de/cowtipper/cowlection/search/GuiSearch.java | 2 +- .../de/cowtipper/cowlection/search/LogFilesSearcher.java | 9 +++++---- src/main/resources/assets/cowlection/lang/en_US.lang | 6 ++++-- 4 files changed, 23 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/main/java/de/cowtipper/cowlection/config/MooConfig.java b/src/main/java/de/cowtipper/cowlection/config/MooConfig.java index b26c19f..d6e93cd 100644 --- a/src/main/java/de/cowtipper/cowlection/config/MooConfig.java +++ b/src/main/java/de/cowtipper/cowlection/config/MooConfig.java @@ -61,6 +61,7 @@ public class MooConfig { public static String[] logsDirs; private static String defaultStartDate; private static int maxLogFileSize; + private static int maxLatestLogFileSize; // Category: Notifications public static boolean doUpdateCheck; public static boolean showBestFriendNotifications; @@ -318,10 +319,13 @@ public class MooConfig { .setValidationPattern(Pattern.compile("^[1-9][0-9]{0,2}|(2[0-9]{3}-(0[1-9]|1[012])-(0[1-9]|[12][0-9]|3[01]))$")); Property propMaxLogFileSize = subCat.addConfigEntry(cfg.get(CATEGORY_LOGS_SEARCH, "maxLogFileSize", 2048, "Max log file size (in KB)?", 50, 10000)); + Property propMaxLatestLogFileSize = subCat.addConfigEntry(cfg.get(CATEGORY_LOGS_SEARCH, + "maxLatestLogFileSize", 50000, "Max latest.log file size (in KB)?", 50, 200000)); logSearchProperties = new ArrayList<>(); logSearchProperties.add(propLogsDirs); logSearchProperties.add(propDefaultStartDate); logSearchProperties.add(propMaxLogFileSize); + logSearchProperties.add(propMaxLatestLogFileSize); // Category: Notifications configCat = new MooConfigCategory("Notifications", "notifications"); @@ -667,6 +671,7 @@ public class MooConfig { logsDirs = propLogsDirs.getStringList(); defaultStartDate = propDefaultStartDate.getString().trim(); maxLogFileSize = propMaxLogFileSize.getInt(); + maxLatestLogFileSize = propMaxLatestLogFileSize.getInt(); // Category: Notifications doUpdateCheck = propDoUpdateCheck.getBoolean(); showBestFriendNotifications = propShowBestFriendNotifications.getBoolean(); @@ -756,6 +761,7 @@ public class MooConfig { propLogsDirs.set(logsDirs); propDefaultStartDate.set(defaultStartDate); propMaxLogFileSize.set(maxLogFileSize); + propMaxLatestLogFileSize.set(maxLatestLogFileSize); // Category: Notifications propDoUpdateCheck.set(doUpdateCheck); propShowBestFriendNotifications.set(showBestFriendNotifications); @@ -913,6 +919,13 @@ public class MooConfig { return maxLogFileSize * 1024L; } + /** + * @return max latest.log file size in Bytes + */ + public static long getMaxLatestLogFileSize() { + return maxLatestLogFileSize * 1024L; + } + // Category: General public static Setting getConfigGuiExplanationsDisplay() { return Setting.get(configGuiExplanations); diff --git a/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java b/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java index 7e721a9..2970c24 100644 --- a/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java +++ b/src/main/java/de/cowtipper/cowlection/search/GuiSearch.java @@ -291,7 +291,7 @@ public class GuiSearch extends GuiScreen { this.searchResults = searchResultsData.getSortedSearchResults(); this.analyzedFiles = "Analyzed files: " + EnumChatFormatting.WHITE + searchResultsData.getAnalyzedFiles(); this.analyzedFilesWithHits = "Files with hits: " + EnumChatFormatting.WHITE + searchResultsData.getAnalyzedFilesWithHits(); - this.skippedFiles = "Skipped files: " + EnumChatFormatting.WHITE + searchResultsData.getSkippedFiles(); + this.skippedFiles = "Skipped large files: " + (searchResultsData.getSkippedFiles() > 0 ? EnumChatFormatting.RED : EnumChatFormatting.WHITE) + searchResultsData.getSkippedFiles(); if (this.searchResults.isEmpty()) { this.searchResults.add(new LogEntry(EnumChatFormatting.ITALIC + "No results")); areEntriesSearchResults = false; diff --git a/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java b/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java index bbfd0fb..c005852 100644 --- a/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java +++ b/src/main/java/de/cowtipper/cowlection/search/LogFilesSearcher.java @@ -32,6 +32,7 @@ class LogFilesSearcher { LogSearchResults searchFor(String searchQuery, boolean chatOnly, boolean matchCase, boolean removeFormatting, LocalDate dateStart, LocalDate dateEnd) throws IOException { LogSearchResults logSearchResults = new LogSearchResults(); long fileSizeLimit = MooConfig.getMaxLogFileSize(); + long latestLogSizeLimit = MooConfig.getMaxLatestLogFileSize(); for (String logsDirPath : MooConfig.logsDirs) { File logsDir = new File(logsDirPath); if (!logsDir.exists() || !logsDir.isDirectory()) { @@ -53,7 +54,7 @@ class LogFilesSearcher { Integer.parseInt(fileNameMatcher.group(2)), Integer.parseInt(fileNameMatcher.group(3))); if (!fileLocalDate.isBefore(dateStart) && !fileLocalDate.isAfter(dateEnd)) { if (path.toFile().length() > fileSizeLimit) { - // file too large + // .log.gz file too large logSearchResults.addSkippedFile(); } else { logSearchResults.addAnalyzedFile(); @@ -64,8 +65,8 @@ class LogFilesSearcher { } else if (fileName.equals("latest.log")) { LocalDate lastModified = Instant.ofEpochMilli(path.toFile().lastModified()).atZone(ZoneId.systemDefault()).toLocalDate(); if (!lastModified.isBefore(dateStart) && !lastModified.isAfter(dateEnd)) { - if (path.toFile().length() > fileSizeLimit) { - // file too large + if (path.toFile().length() > latestLogSizeLimit) { + // latest.log too large logSearchResults.addSkippedFile(); } else { logSearchResults.addAnalyzedFile(); @@ -85,7 +86,7 @@ class LogFilesSearcher { int skippedFileCounter = logSearchResults.getSkippedFiles(); if (skippedFileCounter > 0) { throw new FileNotFoundException(EnumChatFormatting.DARK_RED + "ERROR: No Minecraft log files could be found for the selected date range.\n" - + EnumChatFormatting.RED + skippedFileCounter + EnumChatFormatting.DARK_RED + " log files were skipped because they are too large ( >" + FileUtils.byteCountToDisplaySize(MooConfig.getMaxLogFileSize()) + ").\n" + + EnumChatFormatting.RED + skippedFileCounter + EnumChatFormatting.DARK_RED + " log files were skipped because they are too large (" + EnumChatFormatting.RED + ".log.gz" + EnumChatFormatting.DARK_RED + " files >" + FileUtils.byteCountToDisplaySize(MooConfig.getMaxLogFileSize()) + "; " + EnumChatFormatting.RED + "latest.log" + EnumChatFormatting.DARK_RED + " >" + FileUtils.byteCountToDisplaySize(MooConfig.getMaxLatestLogFileSize()) + ").\n" + EnumChatFormatting.RED + "Please check if the dates as well as the directories of the log files are set correctly (Log Search ➡ Settings [top right corner]).\n" + EnumChatFormatting.DARK_RED + "You could also increase the maximum allowed log file size to be searched (Log Search ➡ Settings), but note that each file must be unzipped before it can be analyzed, which can make the log file search take significantly longer for large files."); } else { diff --git a/src/main/resources/assets/cowlection/lang/en_US.lang b/src/main/resources/assets/cowlection/lang/en_US.lang index 9f7c5cf..0c7d1da 100644 --- a/src/main/resources/assets/cowlection/lang/en_US.lang +++ b/src/main/resources/assets/cowlection/lang/en_US.lang @@ -20,8 +20,10 @@ cowlection.config.logsDirs=Directories with Minecraft log files cowlection.config.logsDirs.tooltip=List of directories containing Minecraft logs cowlection.config.defaultStartDate=Start date for log file search §c[see tooltip!] cowlection.config.defaultStartDate.tooltip=§eCan be either a §6number§e (e.g. "§63§e" means "§6start searching 3 months ago§e"),\n§eor alternatively a §6fixed date §e(§6yyyy-mm-dd§e) -cowlection.config.maxLogFileSize=Maximum log file size (in KB) to analyze -cowlection.config.maxLogFileSize.tooltip=§eLog files larger than this value will be skipped/ignored +cowlection.config.maxLogFileSize=Maximum .log.gz file size (in KB) to analyze +cowlection.config.maxLogFileSize.tooltip=§e.log.gz files larger than this value will be skipped/ignored +cowlection.config.maxLatestLogFileSize=Maximum latest.log file size (in KB) to analyze +cowlection.config.maxLatestLogFileSize.tooltip=§elatest.log files larger than this value will be skipped/ignored cowlection.config.gotoKeyBindings=Change key bindings cowlection.config.gotoKeyBindings.tooltip=Some key bindings can be found in the 'Cowlection' sub-category cowlection.config.doUpdateCheck=Check for updates -- cgit