Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
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 <[email protected]>
  • Loading branch information
Saqoosha and claude committed Jun 1, 2025
commit 1f28ea434ac24ff21d931973f7c001c933019d7a
22 changes: 18 additions & 4 deletions Editor/Services/ConsoleLogsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ namespace McpUnity.Services
public class ConsoleLogsService : IConsoleLogsService
{
// Static mapping for MCP log types to Unity log types
private static readonly Dictionary<string, string> LogTypeMapping = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase)
// Some MCP types map to multiple Unity types (e.g., "error" includes Error, Exception and Assert)
private static readonly Dictionary<string, HashSet<string>> LogTypeMapping = new Dictionary<string, HashSet<string>>(StringComparer.OrdinalIgnoreCase)
{
{ "info", "Log" }
{ "info", new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Log" } },
{ "error", new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Error", "Exception", "Assert" } }
};

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

// Map MCP log types to Unity log types outside the loop for better performance
string unityLogType = filter && LogTypeMapping.TryGetValue(logType, out string mapped) ? mapped : logType;
HashSet<string> unityLogTypes = null;
if (filter)
{
if (LogTypeMapping.TryGetValue(logType, out var mapped))
{
unityLogTypes = mapped;
}
else
{
// If no mapping exists, create a set with the original type for case-insensitive comparison
unityLogTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { logType };
}
}

lock (_logEntries)
{
foreach (var entry in _logEntries)
{
if (filter && !entry.Type.ToString().Equals(unityLogType, System.StringComparison.OrdinalIgnoreCase))
if (filter && !unityLogTypes.Contains(entry.Type.ToString()))
continue;
logsArray.Add(new JObject
{
Expand Down