Asynchronous logger & Improved debug logging for 'E' Events - #272
Open
Unshown wants to merge 8 commits into
Open
Asynchronous logger & Improved debug logging for 'E' Events#272Unshown wants to merge 8 commits into
Unshown wants to merge 8 commits into
Conversation
Previously, the logger opened, wrote to, and closed `Launcher.log` synchronously on every single log call. Under heavy network traffic, this file I/O was stalling the main networking threads, contributing to dropped connections when too many events were received at once. This commit moves the logger to a dedicated background thread. - Added a `std::queue<std::string>` and a `std::condition_variable` to handle log dispatching. - Log calls (`info`, `debug`, etc.) now instantly push their messages to the queue and return immediately, freeing up the network threads. - Added a lightweight `Utils::ToString` helper in `Utils.h` (mirroring the existing `ToWString`) to convert wide strings into standard UTF-8 strings before pushing them into the new logger queue. This significantly improves launcher performance under heavy load without changing the visual log output.
Added targeted debug logging in `GlobalHandler.cpp` for both incoming and outgoing custom events (`C == 'E'`).
Previously, it was difficult to tell when custom events were causing network saturation. This change logs the total size and name of all custom events passing through the launcher. To prevent console spam, the logic intelligently strips out the JSON payload body (truncating at the first `{` or `[`) so only the clean event name and byte size are printed.
Note: Because the logger was moved to an asynchronous background queue in the previous commit, adding this detailed logging is completely safe. It will not block the main network loop or cause connection drops, even if a server mod aggressively spams thousands of events per second.
This should significantly help server owners and mod developers quickly identify network bottlenecks.
WiserTixx
requested changes
Aug 24, 2026
This reverts commit 83a24a0.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
1. Refactor logger to run asynchronously to prevent event loop blocking
Previously, the logger opened, wrote to, and closed
Launcher.logsynchronously on every single log call. Under heavy network traffic, this file I/O was stalling the main networking threads, contributing to dropped connections when too many events were received at once.This commit moves the logger to a dedicated background thread.
std::queue<std::string>and astd::condition_variableto handle log dispatching.info,debug, etc.) now instantly push their messages to the queue and return immediately, freeing up the network threads.Utils::ToStringhelper inUtils.h(mirroring the existingToWString) to convert wide strings into standard UTF-8 strings before pushing them into the new logger queue.This significantly improves launcher performance under heavy load without changing the visual log output.
2. Add debug logging for Lua custom events ('E' packets)
Added targeted debug logging in
GlobalHandler.cppfor both incoming and outgoing custom events (C == 'E').Previously, it was difficult to tell when custom events were causing network saturation. This change logs the total size and name of all custom events passing through the launcher. To prevent console spam, the logic intelligently strips out the JSON payload body (truncating at the first
{or[) so only the clean event name and byte size are printed.Note: Because the logger was moved to an asynchronous background, adding this detailed logging is completely safe. It will not block the main network loop or cause connection drops, even if a server mod aggressively spams thousands of events per second.
This should significantly help server owners and mod developers quickly identify network event spam and help find optimization measures.
By creating this pull request, I understand that code that is AI generated or otherwise automatically generated may be rejected without further discussion.
I declare that I fully understand all code I pushed into this PR, and wrote all this code myself and own the rights to this code.