Skip to content

Commit 1f28ea4

Browse files
Saqooshaclaude
andcommitted
feat: Expand error log type mapping to include Exception and Assert
Per PR review feedback, expanded the log type mapping to handle multi-value mappings. The "error" filter now returns all error-related log types. We found that filtering by "error" was not comprehensive enough for development purposes - Exception and Assert logs are also error conditions that developers need to see. Changes: - Changed LogTypeMapping from Dictionary<string, string> to Dictionary<string, HashSet<string>> to support 1-to-many mappings - Added "error" → {"Error", "Exception", "Assert"} mapping - Updated GetAllLogsAsJson filtering logic to use HashSet.Contains() This ensures developers can see all error-related logs when filtering by "error" type, making debugging more effective. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 1ecfd45 commit 1f28ea4

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

Editor/Services/ConsoleLogsService.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ namespace McpUnity.Services
1313
public class ConsoleLogsService : IConsoleLogsService
1414
{
1515
// Static mapping for MCP log types to Unity log types
16-
private static readonly Dictionary<string, string> LogTypeMapping = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
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)
1718
{
18-
{ "info", "Log" }
19+
{ "info", new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Log" } },
20+
{ "error", new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Error", "Exception", "Assert" } }
1921
};
2022

2123
// Structure to store log information
@@ -83,13 +85,25 @@ public JArray GetAllLogsAsJson(string logType = "")
8385
bool filter = !string.IsNullOrEmpty(logType);
8486

8587
// Map MCP log types to Unity log types outside the loop for better performance
86-
string unityLogType = filter && LogTypeMapping.TryGetValue(logType, out string mapped) ? mapped : logType;
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+
}
87101

88102
lock (_logEntries)
89103
{
90104
foreach (var entry in _logEntries)
91105
{
92-
if (filter && !entry.Type.ToString().Equals(unityLogType, System.StringComparison.OrdinalIgnoreCase))
106+
if (filter && !unityLogTypes.Contains(entry.Type.ToString()))
93107
continue;
94108
logsArray.Add(new JObject
95109
{

0 commit comments

Comments
 (0)