From a39be56b8c22b0c33dd14cd5ecfb24da287aefda Mon Sep 17 00:00:00 2001 From: routersys Date: Tue, 25 Aug 2026 00:05:30 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=AD=E3=82=B0=E3=81=B8=E8=AA=BF=E6=9F=BB?= =?UTF-8?q?=E7=94=A8=E3=81=AE=E8=A1=8C=E3=82=92=E6=AE=8B=E3=81=9B=E3=82=8B?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E3=81=97=E3=81=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Log.cpp | 43 ++++++++++++++++++++++++++++++------------- src/Log.h | 1 + 2 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/Log.cpp b/src/Log.cpp index 6a4dc1f..c9fd506 100644 --- a/src/Log.cpp +++ b/src/Log.cpp @@ -10,6 +10,23 @@ void SetLogHandle(LOG_HANDLE* handle) { g_log = handle; } +#ifdef DL_DEBUG_LOG +static void WriteTrace(const wchar_t* text) { + static wchar_t logPath[MAX_PATH] = {}; + if (!logPath[0]) { + wchar_t dir[MAX_PATH] = {}; + if (GetTempPathW(MAX_PATH, dir)) + _snwprintf_s(logPath, _TRUNCATE, L"%sDockLayout.log", dir); + } + if (!logPath[0]) return; + FILE* f = nullptr; + if (_wfopen_s(&f, logPath, L"a+, ccs=UTF-8") == 0 && f) { + fwprintf(f, L"%s\n", text); + fclose(f); + } +} +#endif + void LogF(const wchar_t* fmt, ...) { wchar_t buf[1024]; va_list ap; va_start(ap, fmt); @@ -17,19 +34,19 @@ void LogF(const wchar_t* fmt, ...) { va_end(ap); if (g_log) g_log->log(g_log, buf); #ifdef DL_DEBUG_LOG - static wchar_t logPath[MAX_PATH] = {}; - if (!logPath[0]) { - wchar_t dir[MAX_PATH] = {}; - if (GetTempPathW(MAX_PATH, dir)) - _snwprintf_s(logPath, _TRUNCATE, L"%sDockLayout.log", dir); - } - if (logPath[0]) { - FILE* f = nullptr; - if (_wfopen_s(&f, logPath, L"a+, ccs=UTF-8") == 0 && f) { - fwprintf(f, L"%s\n", buf); - fclose(f); - } - } + WriteTrace(buf); +#endif +} + +void LogTraceF(const wchar_t* fmt, ...) { +#ifdef DL_DEBUG_LOG + wchar_t buf[1024]; + va_list ap; va_start(ap, fmt); + _vsnwprintf_s(buf, _TRUNCATE, fmt, ap); + va_end(ap); + WriteTrace(buf); +#else + (void)fmt; #endif } diff --git a/src/Log.h b/src/Log.h index 0e855cb..d8d9f80 100644 --- a/src/Log.h +++ b/src/Log.h @@ -8,6 +8,7 @@ namespace dl { void SetLogHandle(LOG_HANDLE* handle); void LogF(const wchar_t* fmt, ...); +void LogTraceF(const wchar_t* fmt, ...); void LogWarn(const wchar_t* text); }