From d44b62fae5bb6207368c3fb91185d4e5ab13c709 Mon Sep 17 00:00:00 2001 From: Reginald Alfret Date: Sat, 14 Nov 2026 16:09:31 +0530 Subject: [PATCH 1/2] fix: allow logcat regex parser to parse empty log messages - Support log entries where message body is empty or has no trailing space after the tag colon - Preserve leading whitespace when message content is present - Add unit tests covering year and threadtime format with empty message bodies - Update CHANGELOG.md --- com.unity.mobile.android-logcat/CHANGELOG.md | 1 + .../Editor/AndroidLogcat.cs | 4 +-- .../Tests/Editor/AndroidLogcatRegexTests.cs | 30 +++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/com.unity.mobile.android-logcat/CHANGELOG.md b/com.unity.mobile.android-logcat/CHANGELOG.md index 9758b2f6..4eed90c0 100644 --- a/com.unity.mobile.android-logcat/CHANGELOG.md +++ b/com.unity.mobile.android-logcat/CHANGELOG.md @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Recordings can be played in the Screen Capture window, with play/pause, a time slider and buttons that step one frame back or forward. - Tools->Open Terminal is now supported on Linux Editor. - Fixed Tools->Open Terminal not opening a window on Windows Editor when running on CoreCLR. + - Fixed logcat regex parser failing on empty log messages or messages without a space after the tag colon. ## [1.4.7] - 2025-12-12 ### Fixes & Improvements diff --git a/com.unity.mobile.android-logcat/Editor/AndroidLogcat.cs b/com.unity.mobile.android-logcat/Editor/AndroidLogcat.cs index 25cfb9fe..56d82915 100644 --- a/com.unity.mobile.android-logcat/Editor/AndroidLogcat.cs +++ b/com.unity.mobile.android-logcat/Editor/AndroidLogcat.cs @@ -462,10 +462,10 @@ internal string LogPrintFormat internal static readonly Regex m_CrashMessageRegex = new Regex(@"^\s*#\d{2}\s*pc\s([a-fA-F0-9]{8}).*(libunity\.so|libmain\.so)", RegexOptions.Compiled); // Regex for messages produced via 'adb logcat -s -v year *:V' - internal static readonly Regex m_LogCatEntryYearRegex = new Regex(@"(?\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\.\d{3})\s+(?\d+)\s+(?\d+)\s+(?[VDIWEFS])\s+(?.+?)\s*:\s(?.*)", RegexOptions.Compiled); + internal static readonly Regex m_LogCatEntryYearRegex = new Regex(@"(?\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\.\d{3})\s+(?\d+)\s+(?\d+)\s+(?[VDIWEFS])\s+(?.+?)\s*:(?: (?.*))?", RegexOptions.Compiled); // Regex for messages produced via 'adb logcat -s -v threadtime *:V' - internal static readonly Regex m_LogCatEntryThreadTimeRegex = new Regex(@"(?\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\.\d{3})\s+(?\d+)\s+(?\d+)\s+(?[VDIWEFS])\s+(?.+?)\s*:\s(?.*)", RegexOptions.Compiled); + internal static readonly Regex m_LogCatEntryThreadTimeRegex = new Regex(@"(?\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\.\d{3})\s+(?\d+)\s+(?\d+)\s+(?[VDIWEFS])\s+(?.+?)\s*:(?: (?.*))?", RegexOptions.Compiled); internal static readonly int kUnityHashCode = "Unity".GetHashCode(); diff --git a/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatRegexTests.cs b/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatRegexTests.cs index 40807f79..70247975 100644 --- a/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatRegexTests.cs +++ b/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatRegexTests.cs @@ -107,6 +107,36 @@ public void WhitespacesArePreservedInMessage() Assert.IsTrue(threadMsg.Equals(myTestMessage)); } + [Test] + public void EmptyMessagesAreParsedCorrectly() + { + // Message ending with colon (no trailing space) + var msgYearNoSpace = @"2018-10-25 14:27:29.803 1277 10543 E ctxmgr :"; + var matchYearNoSpace = AndroidLogcat.m_LogCatEntryYearRegex.Match(msgYearNoSpace); + Assert.IsTrue(matchYearNoSpace.Success); + Assert.AreEqual("ctxmgr", matchYearNoSpace.Groups["tag"].Value); + Assert.AreEqual(string.Empty, matchYearNoSpace.Groups["msg"].Value); + + var msgThreadNoSpace = "10-25 14:27:29.803 1277 10543 E ctxmgr :"; + var matchThreadNoSpace = AndroidLogcat.m_LogCatEntryThreadTimeRegex.Match(msgThreadNoSpace); + Assert.IsTrue(matchThreadNoSpace.Success); + Assert.AreEqual("ctxmgr", matchThreadNoSpace.Groups["tag"].Value); + Assert.AreEqual(string.Empty, matchThreadNoSpace.Groups["msg"].Value); + + // Message ending with colon and single space (empty message body) + var msgYearWithSpace = @"2018-10-25 14:27:29.803 1277 10543 E ctxmgr : "; + var matchYearWithSpace = AndroidLogcat.m_LogCatEntryYearRegex.Match(msgYearWithSpace); + Assert.IsTrue(matchYearWithSpace.Success); + Assert.AreEqual("ctxmgr", matchYearWithSpace.Groups["tag"].Value); + Assert.AreEqual(string.Empty, matchYearWithSpace.Groups["msg"].Value); + + var msgThreadWithSpace = "10-25 14:27:29.803 1277 10543 E ctxmgr : "; + var matchThreadWithSpace = AndroidLogcat.m_LogCatEntryThreadTimeRegex.Match(msgThreadWithSpace); + Assert.IsTrue(matchThreadWithSpace.Success); + Assert.AreEqual("ctxmgr", matchThreadWithSpace.Groups["tag"].Value); + Assert.AreEqual(string.Empty, matchThreadWithSpace.Groups["msg"].Value); + } + [Test] public void CorrectlyParsePidsWithWindowsEndlines() { From 151a02a0d51c41d5f85a9410e602ad9d676d3103 Mon Sep 17 00:00:00 2001 From: Reginald Alfret Date: Mon, 16 Nov 2026 18:02:31 +0530 Subject: [PATCH 2/2] fix: resolve regressions with colons in tags and tab delimiter in logcat regex - Use ':(?:\s(?.*)|$)' so colons in tags (e.g. BarTender:BatteryStatsDumper) continue matching correctly - Preserve \s whitespace delimiter support including tabs (\t) after the colon - Support empty log messages ending with colon or colon with trailing whitespace - Add unit tests for colons in tags with empty message and tab message delimiters --- .../Editor/AndroidLogcat.cs | 4 +-- .../Tests/Editor/AndroidLogcatRegexTests.cs | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/com.unity.mobile.android-logcat/Editor/AndroidLogcat.cs b/com.unity.mobile.android-logcat/Editor/AndroidLogcat.cs index 56d82915..4912c500 100644 --- a/com.unity.mobile.android-logcat/Editor/AndroidLogcat.cs +++ b/com.unity.mobile.android-logcat/Editor/AndroidLogcat.cs @@ -462,10 +462,10 @@ internal string LogPrintFormat internal static readonly Regex m_CrashMessageRegex = new Regex(@"^\s*#\d{2}\s*pc\s([a-fA-F0-9]{8}).*(libunity\.so|libmain\.so)", RegexOptions.Compiled); // Regex for messages produced via 'adb logcat -s -v year *:V' - internal static readonly Regex m_LogCatEntryYearRegex = new Regex(@"(?\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\.\d{3})\s+(?\d+)\s+(?\d+)\s+(?[VDIWEFS])\s+(?.+?)\s*:(?: (?.*))?", RegexOptions.Compiled); + internal static readonly Regex m_LogCatEntryYearRegex = new Regex(@"(?\d{4}-\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\.\d{3})\s+(?\d+)\s+(?\d+)\s+(?[VDIWEFS])\s+(?.+?)\s*:(?:\s(?.*)|$)", RegexOptions.Compiled); // Regex for messages produced via 'adb logcat -s -v threadtime *:V' - internal static readonly Regex m_LogCatEntryThreadTimeRegex = new Regex(@"(?\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\.\d{3})\s+(?\d+)\s+(?\d+)\s+(?[VDIWEFS])\s+(?.+?)\s*:(?: (?.*))?", RegexOptions.Compiled); + internal static readonly Regex m_LogCatEntryThreadTimeRegex = new Regex(@"(?\d{2}-\d{2}\s+\d{2}:\d{2}:\d{2}\.\d{3})\s+(?\d+)\s+(?\d+)\s+(?[VDIWEFS])\s+(?.+?)\s*:(?:\s(?.*)|$)", RegexOptions.Compiled); internal static readonly int kUnityHashCode = "Unity".GetHashCode(); diff --git a/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatRegexTests.cs b/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatRegexTests.cs index 70247975..f01867b4 100644 --- a/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatRegexTests.cs +++ b/com.unity.mobile.android-logcat/Tests/Editor/AndroidLogcatRegexTests.cs @@ -135,6 +135,35 @@ public void EmptyMessagesAreParsedCorrectly() Assert.IsTrue(matchThreadWithSpace.Success); Assert.AreEqual("ctxmgr", matchThreadWithSpace.Groups["tag"].Value); Assert.AreEqual(string.Empty, matchThreadWithSpace.Groups["msg"].Value); + + // Tag containing a colon with empty message + var msgYearTagWithColonNoSpace = @"2018-10-25 14:27:29.803 1277 10543 E BarTender:BatteryStatsDumper:"; + var matchYearTagWithColonNoSpace = AndroidLogcat.m_LogCatEntryYearRegex.Match(msgYearTagWithColonNoSpace); + Assert.IsTrue(matchYearTagWithColonNoSpace.Success); + Assert.AreEqual("BarTender:BatteryStatsDumper", matchYearTagWithColonNoSpace.Groups["tag"].Value); + Assert.AreEqual(string.Empty, matchYearTagWithColonNoSpace.Groups["msg"].Value); + + var msgThreadTagWithColonNoSpace = "10-25 14:27:29.803 1277 10543 E BarTender:BatteryStatsDumper:"; + var matchThreadTagWithColonNoSpace = AndroidLogcat.m_LogCatEntryThreadTimeRegex.Match(msgThreadTagWithColonNoSpace); + Assert.IsTrue(matchThreadTagWithColonNoSpace.Success); + Assert.AreEqual("BarTender:BatteryStatsDumper", matchThreadTagWithColonNoSpace.Groups["tag"].Value); + Assert.AreEqual(string.Empty, matchThreadTagWithColonNoSpace.Groups["msg"].Value); + } + + [Test] + public void TabAfterColonIsParsedAsMessageDelimiter() + { + var msgYearWithTab = "2018-10-25 14:27:29.803 1277 10543 E mytag:\thello"; + var matchYearWithTab = AndroidLogcat.m_LogCatEntryYearRegex.Match(msgYearWithTab); + Assert.IsTrue(matchYearWithTab.Success); + Assert.AreEqual("mytag", matchYearWithTab.Groups["tag"].Value); + Assert.AreEqual("hello", matchYearWithTab.Groups["msg"].Value); + + var msgThreadWithTab = "10-25 14:27:29.803 1277 10543 E mytag:\thello"; + var matchThreadWithTab = AndroidLogcat.m_LogCatEntryThreadTimeRegex.Match(msgThreadWithTab); + Assert.IsTrue(matchThreadWithTab.Success); + Assert.AreEqual("mytag", matchThreadWithTab.Groups["tag"].Value); + Assert.AreEqual("hello", matchThreadWithTab.Groups["msg"].Value); } [Test]