-
Notifications
You must be signed in to change notification settings - Fork 15
Implement GetCurrentConsoleLogs & ClearConsoleLogs #38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
notargs
commented
Jun 14, 2025
- Implement GetCurrentConsoleLogs & ClearConsoleLogs
- Remove GetLogHistory
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR replaces the legacy GetLogHistory feature by introducing two new console log tools and cleaning up related artifacts.
- Add
GetCurrentConsoleLogsandClearConsoleLogsmethods for querying and clearing the Unity Editor console via reflection. - Remove the old
LogCollectorclass and its init call. - Update documentation (
README.mdandREADME.ja.md) and add new supporting types (LogEntry,LogMessageFlags).
Reviewed Changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| McpTools/McpUnityEditorTool.cs | Added GetCurrentConsoleLogs, ClearConsoleLogs, removed GetLogHistory |
| McpTools/LogCollector.cs (+.meta) & .cs | Removed legacy log collector implementation |
| McpTools/LogMessageFlags.cs (+.meta) & .cs | Added new LogMessageFlags enum |
| McpTools/LogEntry.cs (+.meta) & .cs | Added new LogEntry record |
| McpServerRunner.cs | Removed LogCollector.Initialize() call |
| README.md & README.ja.md | Updated tool list entries |
Comments suppressed due to low confidence (2)
UnityNaturalMCPServer/Editor/McpTools/McpUnityEditorTool.cs:38
- There's a typo in the description: "Maches all logs" should be "Matches all logs".
""(Maches all logs), \"error\", \"warning\", \"log\", \"compile-error\"(This is all you need to check for compilation errors.), \"compile-warning\"
UnityNaturalMCPServer/Editor/McpTools/McpUnityEditorTool.cs:35
- [nitpick] There are no tests covering the new
GetCurrentConsoleLogsandClearConsoleLogsfunctionality. Adding unit or integration tests would help validate and prevent regressions.
public async Task<IReadOnlyList<LogEntry>> GetCurrentConsoleLogs(
| var getCountMethod = logEntries.GetMethod("GetCount", BindingFlags.Public | BindingFlags.Static); | ||
| var getEntryInternalMethod = logEntries.GetMethod("GetEntryInternal", BindingFlags.Public | BindingFlags.Static); |
Copilot
AI
Jun 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Internal UnityEditor APIs like GetCount and GetEntryInternal are not public. Update BindingFlags to include BindingFlags.NonPublic (e.g., BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) to reliably locate these methods.
| var getCountMethod = logEntries.GetMethod("GetCount", BindingFlags.Public | BindingFlags.Static); | |
| var getEntryInternalMethod = logEntries.GetMethod("GetEntryInternal", BindingFlags.Public | BindingFlags.Static); | |
| var getCountMethod = logEntries.GetMethod("GetCount", BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic); | |
| var getEntryInternalMethod = logEntries.GetMethod("GetEntryInternal", BindingFlags.Public | BindingFlags.Static | BindingFlags.NonPublic); |
| Assert.IsNotNull(logEntries); | ||
|
|
||
| var getCountMethod = logEntries.GetMethod("GetCount", BindingFlags.Public | BindingFlags.Static); | ||
| var getEntryInternalMethod = logEntries.GetMethod("GetEntryInternal", BindingFlags.Public | BindingFlags.Static); |
Copilot
AI
Jun 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GetEntryInternal is an internal method. You should include BindingFlags.NonPublic when calling GetMethod to avoid a null result at runtime.
| var getEntryInternalMethod = logEntries.GetMethod("GetEntryInternal", BindingFlags.Public | BindingFlags.Static); | |
| var getEntryInternalMethod = logEntries.GetMethod("GetEntryInternal", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); |
| var logEntries = Type.GetType("UnityEditor.LogEntries,UnityEditor.dll"); | ||
| Assert.IsNotNull(logEntries); | ||
|
|
||
| var getCountMethod = logEntries.GetMethod("GetCount", BindingFlags.Public | BindingFlags.Static); | ||
| var getEntryInternalMethod = logEntries.GetMethod("GetEntryInternal", BindingFlags.Public | BindingFlags.Static); | ||
|
|
Copilot
AI
Jun 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The reflection logic to get the LogEntries type and methods is duplicated in both GetCurrentConsoleLogs and ClearConsoleLogs. Consider extracting a helper to reduce code duplication.
| var logEntries = Type.GetType("UnityEditor.LogEntries,UnityEditor.dll"); | |
| Assert.IsNotNull(logEntries); | |
| var getCountMethod = logEntries.GetMethod("GetCount", BindingFlags.Public | BindingFlags.Static); | |
| var getEntryInternalMethod = logEntries.GetMethod("GetEntryInternal", BindingFlags.Public | BindingFlags.Static); | |
| var (logEntries, getCountMethod, getEntryInternalMethod) = GetLogEntriesReflectionData(); | |
| Assert.IsNotNull(logEntries); |