-
-
Notifications
You must be signed in to change notification settings - Fork 65
Add new console log cache to persist log data #264
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
base: main
Are you sure you want to change the base?
Conversation
|
Sorry for the merge conflict. I were needed urgently to fix a bug in the |
128b08d to
2d16670
Compare
|
@IvanMurzak I've made some changes here that should enable log snapshots to be leveraged on domain reload. We are utilizing R3 Timer instead of UnityEditor dependencies, as well as Task.Run to handle our read/write utilizing background threads. In testing, I also noticed the recent bugfix included two subscriptions for console log handling, causing duplicate logs to be stored in memory. I removed the original subscription in favor of the |
01802c4 to
1317f19
Compare
Good point. You made it right. That was a mistake which I made in the last update. I thought the Lets fix the runtime environment. This branch probably still has UnityEditor dependency in Runtime, that is why it fails non Unity Editor tests. |
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 adds a console log cache system to persist Unity log data across domain reloads. The implementation uses periodic snapshots (every 1 second) to write log data to a temporary file, avoiding I/O overhead from writing individual log entries.
Key Changes:
- Introduces a timer-based log cache system that periodically snapshots logs to disk
- Adds log restoration functionality that repopulates logs from cache on domain reload
- Updates test coverage to validate log retention behavior
Reviewed Changes
Copilot reviewed 6 out of 7 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| LogCache.cs | New class implementing periodic log caching with file I/O operations |
| LogWrapper.cs | Simple serialization wrapper for log entries array |
| LogUtils.cs | Modified to integrate with cache system and restore logs on initialization |
| TestToolConsoleIntegration.cs | Added tests for log count validation and cache retention behavior |
Unity-MCP-Plugin/Assets/root/Tests/Editor/Tool/Console/TestToolConsoleIntegration.cs
Outdated
Show resolved
Hide resolved
|
@jstricklin we may still lose logs in the time range in between: Let's utilize another trigger -
Let's follow cascade approach where there is a single entry point (the event). Don't subscribe on that event indecently in your code. It will help us to track the event tree from one place much easier for the future maintenance. Here is the sample: |
1317f19 to
a48c4e7
Compare
Unity-MCP-Plugin/Assets/root/Tests/Editor/Tool/Console/TestToolConsoleIntegration.cs
Outdated
Show resolved
Hide resolved
Unity-MCP-Plugin/Assets/root/Tests/Editor/Tool/Console/TestToolConsoleIntegration.cs
Outdated
Show resolved
Hide resolved
24f064b to
68efb82
Compare
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
Copilot reviewed 7 out of 8 changed files in this pull request and generated 4 comments.
5edd643 to
c571cf2
Compare
…pdate editor-logs.txt filepath
Co-authored-by: Copilot <[email protected]>
…zak/Unity-MCP into fix/persist-console-logs
…hods Co-authored-by: IvanMurzak <[email protected]>
[WIP] Address feedback on LogCache class refactor
…rity in LogUtils and TestToolConsole
Changed LogCache from static to instance-based, updated LogUtils to use a LogCache instance, and improved resource management. Also updated error messages in UnityMcpPlugin for clarity.
Refactor LogCache to instance-based usage
…gEntry properties; add comprehensive tests for log retention and integrity
…nc file operations for improved performance and memory efficiency
…ensure proper disposal
Refactor: Simplify LogCache class
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
Copilot reviewed 12 out of 12 changed files in this pull request and generated 16 comments.
Unity-MCP-Plugin/Assets/root/Tests/Editor/Tool/Console/TestToolConsoleIntegration.cs
Show resolved
Hide resolved
| _fileLock.Dispose(); | ||
| } | ||
|
|
||
| ~LogCache() => Dispose(); |
Copilot
AI
Nov 10, 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.
Resource leak: finalizer calls Dispose() which may access already-disposed managed resources. The finalizer at line 145 calls Dispose(), but this is unsafe because it may try to dispose managed objects (_fileLock, _shutdownCts, timerSubscription) that could already be finalized. Consider implementing the standard Dispose pattern with a Dispose(bool disposing) method, and only dispose managed resources when disposing is true.
Unity-MCP-Plugin/Assets/root/Tests/Editor/Tool/Console/TestLogUtils.cs
Outdated
Show resolved
Hide resolved
Unity-MCP-Plugin/Assets/root/Tests/Editor/Tool/Console/TestLogUtils.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Copilot <[email protected]>
…n tick if previous save is not finished
Initial solution to allow console log persistence across domain reloads
Due to I/O overhead and to avoid issues with deadlock related to Read/Write to file for every individual log instance, this initial approach will focus on creating snapshots of the current stored console logs in LogUtils
_logEntries.This snapshot of current logs will be created in variable intervals currently set to 2 seconds and will be stored to a text file at our
Assets/Temp~/mcp-serverdirectory. Upon domain reload, our LogUtils static class will repopulate its empty_logEntriesConcurrentQueue from the data stored in the cache when present.We can continue to iterating on this solution as needed, but my primary concern with the original design (write to log file on every new log with rotating window) is that to count the logs stored in cache, we need to read from and write to the file on every instance of a log event - and when we reach our window limit, we are ultimately rewriting our entire file with every single transaction, incurring some potential performance overhead.
This led to testing a simple alternate solution of creating snapshots of our logs in memory in intervals, and then retrieving from the cache only upon reload.
Update also includes fix for duplicate console logs being cached in memory