|
20 | 20 | // #include <sys/socket.h>
|
21 | 21 | #include <arpa/inet.h>
|
22 | 22 | #include <random>
|
| 23 | +#include <iomanip> |
23 | 24 |
|
24 | 25 | // ---------------------------------------------------------------------
|
25 | 26 | // WsjcppFilePermissions
|
@@ -398,11 +399,14 @@ std::string WsjcppCore::currentTime_logformat() {
|
398 | 399 |
|
399 | 400 | // ---------------------------------------------------------------------
|
400 | 401 |
|
401 |
| -std::string WsjcppCore::threadId() { |
| 402 | +std::string WsjcppCore::getThreadId() { |
| 403 | + |
| 404 | + static_assert(sizeof(std::thread::id)==sizeof(uint64_t),"this function only works if size of thead::id is equal to the size of uint_64"); |
402 | 405 | std::thread::id this_id = std::this_thread::get_id();
|
| 406 | + uint64_t val = *((uint64_t*) &this_id); |
403 | 407 | std::stringstream stream;
|
404 |
| - stream << std::hex << this_id; |
405 |
| - return "0x" + std::string(stream.str()); |
| 408 | + stream << "0x" << std::setw(16) << std::setfill('0') << std::hex << val; |
| 409 | + return std::string(stream.str()); |
406 | 410 | }
|
407 | 411 |
|
408 | 412 | // ---------------------------------------------------------------------
|
@@ -1159,7 +1163,7 @@ void WsjcppLog::add(WsjcppColorModifier &clr, const std::string &sType, const st
|
1159 | 1163 | std::lock_guard<std::mutex> lock(WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logMutex);
|
1160 | 1164 | WsjcppColorModifier def(WsjcppColorCode::FG_DEFAULT);
|
1161 | 1165 |
|
1162 |
| - std::string sLogMessage = WsjcppCore::currentTime_logformat() + ", " + WsjcppCore::threadId() |
| 1166 | + std::string sLogMessage = WsjcppCore::currentTime_logformat() + ", " + WsjcppCore::getThreadId() |
1163 | 1167 | + " [" + sType + "] " + sTag + ": " + sMessage;
|
1164 | 1168 | std::cout << clr << sLogMessage << def << std::endl;
|
1165 | 1169 |
|
|
0 commit comments