Created
June 15, 2025 18:51
-
-
Save Thaina/a1a1b01326f81e3c1bae4d217ffb420c to your computer and use it in GitHub Desktop.
Unity LogAnalyzer with reflection to LogEntry
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Reflection; | |
using UnityEditor; | |
using UnityEngine; | |
public static class LogAnalyzer | |
{ | |
[MenuItem("TestTest/GroupLogCode")] | |
public static void GroupLogCode() | |
{ | |
var publicStatic = BindingFlags.Static | BindingFlags.Public; | |
var logEntries = Type.GetType("UnityEditor.LogEntries,UnityEditor.dll"); | |
var entryType = Type.GetType("UnityEditor.LogEntry,UnityEditor.dll"); | |
var entryInstance = Activator.CreateInstance(entryType); | |
var getEntryMethod = logEntries.GetMethod("GetEntryInternal", publicStatic); | |
int count = (int)logEntries.GetMethod("GetCount", publicStatic).Invoke(null, null); | |
var dict = Enumerable.Range(0,count).Select((i) => { | |
getEntryMethod.Invoke(null,new object[] { i,entryInstance }); | |
string message = entryType.GetField("message").GetValue(entryInstance).ToString(); | |
var messages = message.Split(":"); | |
return (messages?.ElementAtOrDefault(1),message); | |
}).GroupBy((pair) => pair.Item1,(pair) => pair.message).ToDictionary((group) => group.Key,(group) => group.ToList()); | |
foreach(var pair in dict.OrderByDescending((pair) => pair.Value.Count)) | |
{ | |
Debug.Log(pair.Value.Count + " : " + pair.Key); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment