Skip to content

Commit b8b9cf8

Browse files
Merge pull request #40 from Saqoosha/fix/info-log-type-mapping
fix: Map 'info' log type to Unity's 'Log' type for console log retrieval
2 parents cb4b03c + 1f28ea4 commit b8b9cf8

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

Editor/Services/ConsoleLogsService.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ namespace McpUnity.Services
1212
/// </summary>
1313
public class ConsoleLogsService : IConsoleLogsService
1414
{
15+
// Static mapping for MCP log types to Unity log types
16+
// Some MCP types map to multiple Unity types (e.g., "error" includes Error, Exception and Assert)
17+
private static readonly Dictionary<string, HashSet<string>> LogTypeMapping = new Dictionary<string, HashSet<string>>(StringComparer.OrdinalIgnoreCase)
18+
{
19+
{ "info", new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Log" } },
20+
{ "error", new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Error", "Exception", "Assert" } }
21+
};
22+
1523
// Structure to store log information
1624
private class LogEntry
1725
{
@@ -76,11 +84,26 @@ public JArray GetAllLogsAsJson(string logType = "")
7684
JArray logsArray = new JArray();
7785
bool filter = !string.IsNullOrEmpty(logType);
7886

87+
// Map MCP log types to Unity log types outside the loop for better performance
88+
HashSet<string> unityLogTypes = null;
89+
if (filter)
90+
{
91+
if (LogTypeMapping.TryGetValue(logType, out var mapped))
92+
{
93+
unityLogTypes = mapped;
94+
}
95+
else
96+
{
97+
// If no mapping exists, create a set with the original type for case-insensitive comparison
98+
unityLogTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { logType };
99+
}
100+
}
101+
79102
lock (_logEntries)
80103
{
81104
foreach (var entry in _logEntries)
82105
{
83-
if (filter && !entry.Type.ToString().Equals(logType, System.StringComparison.OrdinalIgnoreCase))
106+
if (filter && !unityLogTypes.Contains(entry.Type.ToString()))
84107
continue;
85108
logsArray.Add(new JObject
86109
{

0 commit comments

Comments
 (0)