From 11e8b122fe932e3c554c08d711f4b73a1675f34e Mon Sep 17 00:00:00 2001 From: yuanyuanxiang <962914132@qq.com> Date: Thu, 20 Aug 2026 17:54:33 +0200 Subject: [PATCH] Fix: Client log dialog stops updating past edit-control default limit The Win32 EDIT control caps text at ~32K/64K chars by default, so the client log dialog silently stopped accepting appends long before the 512KB truncation logic could run. Call SetLimitText(0) in both CClientLog and CActivityDialog to lift the cap. Also unify newline handling in Logger: each entry now ends with exactly one '\n' at the source, so the in-memory ring-buffer dump (used by the TCP log query) splits into lines correctly instead of relying on every Mprintf caller ending its format with '\n'. writeToFile drops the extra std::endl accordingly. Additionally fix a CFont leak in CClientLog::OnInitDialog by moving the font to a member. Co-Authored-By: Claude Opus 4.8 --- common/logger.h | 8 +++++++- server/2015Remote/CActivityDialog.cpp | 2 ++ server/2015Remote/CClientLog.cpp | 6 +++--- server/2015Remote/CClientLog.h | 1 + 4 files changed, 13 insertions(+), 4 deletions(-) diff --git a/common/logger.h b/common/logger.h index f8c539f..527cb66 100644 --- a/common/logger.h +++ b/common/logger.h @@ -152,6 +152,12 @@ public: id + "[" + timestamp + "] [" + file + ":" + std::to_string(line) + "] " + message: id + "[" + timestamp + "] " + message; + // 方案B:在源头统一保证每条日志以单个 '\n' 结尾,文件与内存 ring buffer + // 共用同一份文本;写文件时不再额外追加换行,内存导出直接拼接即可正确分行。 + while (!logEntry.empty() && (logEntry.back() == '\n' || logEntry.back() == '\r')) + logEntry.pop_back(); + logEntry += '\n'; + // Always record to in-memory ring buffer regardless of enable flag. { std::lock_guard lock(m_memMutex); @@ -305,7 +311,7 @@ private: std::lock_guard lock(fileMutex); std::ofstream logFile(logFileName, std::ios::app); if (logFile.is_open()) { - logFile << logEntry << std::endl; + logFile << logEntry; // logEntry 已在 log() 中以单个 '\n' 结尾 } } diff --git a/server/2015Remote/CActivityDialog.cpp b/server/2015Remote/CActivityDialog.cpp index 05292cd..adbcbd6 100644 --- a/server/2015Remote/CActivityDialog.cpp +++ b/server/2015Remote/CActivityDialog.cpp @@ -39,6 +39,8 @@ BOOL CActivityDialog::OnInitDialog() m_editLog.SetFont(&m_font); // 重建为 Unicode 编辑框:这是 ✻/✦ 能正确显示的关键。重建时已保留上面的字体。 RebuildEdit(m_editLog); + // 解除 EDIT 控件默认约 64KB 长度上限,否则大快照经 SetWindowTextW 会被静默截断。 + m_editLog.SetLimitText(0); return TRUE; } diff --git a/server/2015Remote/CClientLog.cpp b/server/2015Remote/CClientLog.cpp index c189e5c..bc1d2c9 100644 --- a/server/2015Remote/CClientLog.cpp +++ b/server/2015Remote/CClientLog.cpp @@ -37,9 +37,9 @@ BOOL CClientLog::OnInitDialog() HICON hIcon = AfxGetApp()->LoadIcon(IDI_CLIENTLOG); SetIcon(hIcon, TRUE); SetIcon(hIcon, FALSE); - CFont* pFont = new CFont(); - pFont->CreatePointFont(85, _T("Consolas")); - m_editLog.SetFont(pFont); + m_font.CreatePointFont(85, _T("Consolas")); + m_editLog.SetFont(&m_font); + m_editLog.SetLimitText(0); // 解除 EDIT 控件默认长度上限,改由 AppendLog 的 512KB 逻辑管理 return TRUE; } diff --git a/server/2015Remote/CClientLog.h b/server/2015Remote/CClientLog.h index d791403..3d09c05 100644 --- a/server/2015Remote/CClientLog.h +++ b/server/2015Remote/CClientLog.h @@ -24,6 +24,7 @@ protected: private: CEdit m_editLog; + CFont m_font; #ifdef AFX_DESIGN_TIME enum { IDD = IDD_DIALOG_CLIENT_LOG };