From 0c4421d5c24e051d912ca4348d29732c91be0c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=A8=E5=A4=B4=E4=BA=91?= <372449116@qq.com> Date: Mon, 15 Dec 2025 09:40:37 +0000 Subject: [PATCH] refactor(log): fix remaining complex log format calls - Fix multi-parameter log calls with complex formatting in POSIX and Windows platforms - Replace remaining ipc::error() and ipc::log() calls with log.error() and log.warning() - Handle special cases: - POSIX condition.h: pthread_cond_timedwait multi-param formatting - POSIX get_wait_time.h: calc_wait_time multi-param formatting - POSIX semaphore_impl.h: sem_timedwait multi-param formatting - Windows mutex.h: WaitForSingleObject with hex formatting, WAIT_ABANDONED as warning - Windows semaphore.h: WaitForSingleObject and ReleaseSemaphore calls - Use std::hex/std::dec for hexadecimal formatting in Windows platform - All log interface migrations now complete --- src/libipc/platform/posix/condition.h | 3 +-- src/libipc/platform/posix/get_wait_time.h | 3 +-- src/libipc/platform/posix/semaphore_impl.h | 3 +-- src/libipc/platform/win/mutex.h | 8 ++++---- src/libipc/platform/win/semaphore.h | 4 ++-- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/libipc/platform/posix/condition.h b/src/libipc/platform/posix/condition.h index e53980d..3500322 100644 --- a/src/libipc/platform/posix/condition.h +++ b/src/libipc/platform/posix/condition.h @@ -123,8 +123,7 @@ public: int eno; if ((eno = ::pthread_cond_timedwait(cond_, static_cast(mtx.native()), &ts)) != 0) { if (eno != ETIMEDOUT) { - ipc::error("fail pthread_cond_timedwait[%d]: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n", - eno, tm, ts.tv_sec, ts.tv_nsec); + log.error("fail pthread_cond_timedwait[", eno, "]: tm = ", tm, ", tv_sec = ", ts.tv_sec, ", tv_nsec = ", ts.tv_nsec); } return false; } diff --git a/src/libipc/platform/posix/get_wait_time.h b/src/libipc/platform/posix/get_wait_time.h index 09dcacf..2e5e76d 100644 --- a/src/libipc/platform/posix/get_wait_time.h +++ b/src/libipc/platform/posix/get_wait_time.h @@ -29,8 +29,7 @@ inline bool calc_wait_time(timespec &ts, std::uint64_t tm /*ms*/) noexcept { inline timespec make_timespec(std::uint64_t tm /*ms*/) noexcept(false) { timespec ts {}; if (!calc_wait_time(ts, tm)) { - ipc::error("fail calc_wait_time: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n", - tm, ts.tv_sec, ts.tv_nsec); + log.error("fail calc_wait_time: tm = ", tm, ", tv_sec = ", ts.tv_sec, ", tv_nsec = ", ts.tv_nsec); throw std::system_error{static_cast(errno), std::system_category()}; } return ts; diff --git a/src/libipc/platform/posix/semaphore_impl.h b/src/libipc/platform/posix/semaphore_impl.h index a61f73c..5358351 100644 --- a/src/libipc/platform/posix/semaphore_impl.h +++ b/src/libipc/platform/posix/semaphore_impl.h @@ -107,8 +107,7 @@ public: auto ts = posix_::detail::make_timespec(tm); if (::sem_timedwait(h_, &ts) != 0) { if (errno != ETIMEDOUT) { - ipc::error("fail sem_timedwait[%d]: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n", - errno, tm, ts.tv_sec, ts.tv_nsec); + log.error("fail sem_timedwait[", errno, "]: tm = ", tm, ", tv_sec = ", ts.tv_sec, ", tv_nsec = ", ts.tv_nsec); } return false; } diff --git a/src/libipc/platform/win/mutex.h b/src/libipc/platform/win/mutex.h index 8d5e9c1..123b213 100644 --- a/src/libipc/platform/win/mutex.h +++ b/src/libipc/platform/win/mutex.h @@ -67,13 +67,13 @@ public: case WAIT_TIMEOUT: return false; case WAIT_ABANDONED: - ipc::log("fail WaitForSingleObject[%lu]: WAIT_ABANDONED, try again.\n", ::GetLastError()); + log.warning("fail WaitForSingleObject[", ::GetLastError(), "]: WAIT_ABANDONED, try again."); if (!unlock()) { return false; } break; // loop again default: - ipc::error("fail WaitForSingleObject[%lu]: 0x%08X\n", ::GetLastError(), ret); + log.error("fail WaitForSingleObject[", ::GetLastError(), "]: 0x", std::hex, ret, std::dec); return false; } } @@ -90,14 +90,14 @@ public: unlock(); LIBIPC_FALLTHROUGH; default: - ipc::error("fail WaitForSingleObject[%lu]: 0x%08X\n", ::GetLastError(), ret); + log.error("fail WaitForSingleObject[", ::GetLastError(), "]: 0x", std::hex, ret, std::dec); throw std::system_error{static_cast(ret), std::system_category()}; } } bool unlock() noexcept { if (!::ReleaseMutex(h_)) { - ipc::error("fail ReleaseMutex[%lu]\n", ::GetLastError()); + log.error("fail ReleaseMutex[", ::GetLastError(), "]"); return false; } return true; diff --git a/src/libipc/platform/win/semaphore.h b/src/libipc/platform/win/semaphore.h index 29f5427..753d1e0 100644 --- a/src/libipc/platform/win/semaphore.h +++ b/src/libipc/platform/win/semaphore.h @@ -66,14 +66,14 @@ public: return false; case WAIT_ABANDONED: default: - ipc::error("fail WaitForSingleObject[%lu]: 0x%08X\n", ::GetLastError(), ret); + log.error("fail WaitForSingleObject[", ::GetLastError(), "]: 0x", std::hex, ret, std::dec); return false; } } bool post(std::uint32_t count) noexcept { if (!::ReleaseSemaphore(h_, static_cast(count), NULL)) { - ipc::error("fail ReleaseSemaphore[%lu]\n", ::GetLastError()); + log.error("fail ReleaseSemaphore[", ::GetLastError(), "]");"}] return false; } return true;