Skip to content

Commit 0c4421d

Browse files
committed
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
1 parent e9a7dba commit 0c4421d

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

src/libipc/platform/posix/condition.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ class condition {
123123
int eno;
124124
if ((eno = ::pthread_cond_timedwait(cond_, static_cast<pthread_mutex_t *>(mtx.native()), &ts)) != 0) {
125125
if (eno != ETIMEDOUT) {
126-
ipc::error("fail pthread_cond_timedwait[%d]: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n",
127-
eno, tm, ts.tv_sec, ts.tv_nsec);
126+
log.error("fail pthread_cond_timedwait[", eno, "]: tm = ", tm, ", tv_sec = ", ts.tv_sec, ", tv_nsec = ", ts.tv_nsec);
128127
}
129128
return false;
130129
}

src/libipc/platform/posix/get_wait_time.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ inline bool calc_wait_time(timespec &ts, std::uint64_t tm /*ms*/) noexcept {
2929
inline timespec make_timespec(std::uint64_t tm /*ms*/) noexcept(false) {
3030
timespec ts {};
3131
if (!calc_wait_time(ts, tm)) {
32-
ipc::error("fail calc_wait_time: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n",
33-
tm, ts.tv_sec, ts.tv_nsec);
32+
log.error("fail calc_wait_time: tm = ", tm, ", tv_sec = ", ts.tv_sec, ", tv_nsec = ", ts.tv_nsec);
3433
throw std::system_error{static_cast<int>(errno), std::system_category()};
3534
}
3635
return ts;

src/libipc/platform/posix/semaphore_impl.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,7 @@ class semaphore {
107107
auto ts = posix_::detail::make_timespec(tm);
108108
if (::sem_timedwait(h_, &ts) != 0) {
109109
if (errno != ETIMEDOUT) {
110-
ipc::error("fail sem_timedwait[%d]: tm = %zd, tv_sec = %ld, tv_nsec = %ld\n",
111-
errno, tm, ts.tv_sec, ts.tv_nsec);
110+
log.error("fail sem_timedwait[", errno, "]: tm = ", tm, ", tv_sec = ", ts.tv_sec, ", tv_nsec = ", ts.tv_nsec);
112111
}
113112
return false;
114113
}

src/libipc/platform/win/mutex.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ class mutex {
6767
case WAIT_TIMEOUT:
6868
return false;
6969
case WAIT_ABANDONED:
70-
ipc::log("fail WaitForSingleObject[%lu]: WAIT_ABANDONED, try again.\n", ::GetLastError());
70+
log.warning("fail WaitForSingleObject[", ::GetLastError(), "]: WAIT_ABANDONED, try again.");
7171
if (!unlock()) {
7272
return false;
7373
}
7474
break; // loop again
7575
default:
76-
ipc::error("fail WaitForSingleObject[%lu]: 0x%08X\n", ::GetLastError(), ret);
76+
log.error("fail WaitForSingleObject[", ::GetLastError(), "]: 0x", std::hex, ret, std::dec);
7777
return false;
7878
}
7979
}
@@ -90,14 +90,14 @@ class mutex {
9090
unlock();
9191
LIBIPC_FALLTHROUGH;
9292
default:
93-
ipc::error("fail WaitForSingleObject[%lu]: 0x%08X\n", ::GetLastError(), ret);
93+
log.error("fail WaitForSingleObject[", ::GetLastError(), "]: 0x", std::hex, ret, std::dec);
9494
throw std::system_error{static_cast<int>(ret), std::system_category()};
9595
}
9696
}
9797

9898
bool unlock() noexcept {
9999
if (!::ReleaseMutex(h_)) {
100-
ipc::error("fail ReleaseMutex[%lu]\n", ::GetLastError());
100+
log.error("fail ReleaseMutex[", ::GetLastError(), "]");
101101
return false;
102102
}
103103
return true;

src/libipc/platform/win/semaphore.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ class semaphore {
6666
return false;
6767
case WAIT_ABANDONED:
6868
default:
69-
ipc::error("fail WaitForSingleObject[%lu]: 0x%08X\n", ::GetLastError(), ret);
69+
log.error("fail WaitForSingleObject[", ::GetLastError(), "]: 0x", std::hex, ret, std::dec);
7070
return false;
7171
}
7272
}
7373

7474
bool post(std::uint32_t count) noexcept {
7575
if (!::ReleaseSemaphore(h_, static_cast<LONG>(count), NULL)) {
76-
ipc::error("fail ReleaseSemaphore[%lu]\n", ::GetLastError());
76+
log.error("fail ReleaseSemaphore[", ::GetLastError(), "]");"}]
7777
return false;
7878
}
7979
return true;

0 commit comments

Comments
 (0)