From be803b32791e4ed2b34867354df3f19293cff604 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Tue, 15 Apr 2025 15:27:47 +0100 Subject: [PATCH 1/3] Optimise guessLevel Signed-off-by: TheKodeToad --- launcher/minecraft/MinecraftInstance.cpp | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index d1780d497..b155e535a 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -36,6 +36,7 @@ */ #include "MinecraftInstance.h" +#include #include "Application.h" #include "BuildConfig.h" #include "QObjectPtr.h" @@ -1014,8 +1015,18 @@ QMap MinecraftInstance::createCensorFilterFromSession(AuthSess MessageLevel::Enum MinecraftInstance::guessLevel(const QString& line, MessageLevel::Enum level) { - QRegularExpression re("\\[(?[0-9:]+)\\] \\[[^/]+/(?[^\\]]+)\\]"); - auto match = re.match(line); + if (line.contains("overwriting existing")) + return MessageLevel::Fatal; + + // NOTE: this diverges from the real regexp. no unicode, the first section is + instead of * + static const QRegularExpression JAVA_EXCEPTION( + R"(Exception in thread|...\d more$|(\s+at |Caused by: )([a-zA-Z_$][a-zA-Z\\d_$]*\.)+[a-zA-Z_$][a-zA-Z\\d_$]*)"); + + if (line.contains(JAVA_EXCEPTION)) + return MessageLevel::Error; + + static const QRegularExpression LINE_WITH_LEVEL("\\[(?[0-9:]+)\\] \\[[^/]+/(?[^\\]]+)\\]"); + auto match = LINE_WITH_LEVEL.match(line); if (match.hasMatch()) { // New style logs from log4j QString timestamp = match.captured("timestamp"); @@ -1042,15 +1053,6 @@ MessageLevel::Enum MinecraftInstance::guessLevel(const QString& line, MessageLev if (line.contains("[DEBUG]")) level = MessageLevel::Debug; } - if (line.contains("overwriting existing")) - return MessageLevel::Fatal; - // NOTE: this diverges from the real regexp. no unicode, the first section is + instead of * - static const QString javaSymbol = "([a-zA-Z_$][a-zA-Z\\d_$]*\\.)+[a-zA-Z_$][a-zA-Z\\d_$]*"; - if (line.contains("Exception in thread") || line.contains(QRegularExpression("\\s+at " + javaSymbol)) || - line.contains(QRegularExpression("Caused by: " + javaSymbol)) || - line.contains(QRegularExpression("([a-zA-Z_$][a-zA-Z\\d_$]*\\.)+[a-zA-Z_$]?[a-zA-Z\\d_$]*(Exception|Error|Throwable)")) || - line.contains(QRegularExpression("... \\d+ more$"))) - return MessageLevel::Error; return level; } From ce76320b23282c678f64d92312af450d8635faa7 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Tue, 15 Apr 2025 15:58:11 +0100 Subject: [PATCH 2/3] Remove unnecessary import Signed-off-by: TheKodeToad --- launcher/minecraft/MinecraftInstance.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index b155e535a..7b02e93ba 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -36,7 +36,6 @@ */ #include "MinecraftInstance.h" -#include #include "Application.h" #include "BuildConfig.h" #include "QObjectPtr.h" From 0f847d66820c73701e336c59f7740d90e8b4cae8 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Fri, 18 Apr 2025 19:40:19 +0100 Subject: [PATCH 3/3] Fix mistakes Signed-off-by: TheKodeToad --- launcher/minecraft/MinecraftInstance.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/minecraft/MinecraftInstance.cpp b/launcher/minecraft/MinecraftInstance.cpp index 7b02e93ba..6f367a1bd 100644 --- a/launcher/minecraft/MinecraftInstance.cpp +++ b/launcher/minecraft/MinecraftInstance.cpp @@ -1019,7 +1019,7 @@ MessageLevel::Enum MinecraftInstance::guessLevel(const QString& line, MessageLev // NOTE: this diverges from the real regexp. no unicode, the first section is + instead of * static const QRegularExpression JAVA_EXCEPTION( - R"(Exception in thread|...\d more$|(\s+at |Caused by: )([a-zA-Z_$][a-zA-Z\\d_$]*\.)+[a-zA-Z_$][a-zA-Z\\d_$]*)"); + R"(Exception in thread|...\d more$|(\s+at |Caused by: )([a-zA-Z_$][a-zA-Z\d_$]*\.)+[a-zA-Z_$][a-zA-Z\d_$]*)|([a-zA-Z_$][a-zA-Z\d_$]*\.)+[a-zA-Z_$][a-zA-Z\d_$]*(Exception|Error|Throwable)"); if (line.contains(JAVA_EXCEPTION)) return MessageLevel::Error;