Skip to content

Commit 88ca764

Browse files
committed
Renamed threadId to getThreadId and try fix convert to string like this '0x7fe,0c8,801,e00'
1 parent b33cf4d commit 88ca764

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,7 @@ int main(int argc, char* argv[]) {
3030
WsjcppCore::recoursiveCopyFiles("./tmp", "./tmp2");
3131
WsjcppCore::recoursiveRemoveDir("./tmp2");
3232

33+
WsjcppCore::getThreadId();
34+
3335
return 0;
3436
}

src/wsjcpp_core.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// #include <sys/socket.h>
2121
#include <arpa/inet.h>
2222
#include <random>
23+
#include <iomanip>
2324

2425
// ---------------------------------------------------------------------
2526
// WsjcppFilePermissions
@@ -398,11 +399,14 @@ std::string WsjcppCore::currentTime_logformat() {
398399

399400
// ---------------------------------------------------------------------
400401

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");
402405
std::thread::id this_id = std::this_thread::get_id();
406+
uint64_t val = *((uint64_t*) &this_id);
403407
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());
406410
}
407411

408412
// ---------------------------------------------------------------------
@@ -1159,7 +1163,7 @@ void WsjcppLog::add(WsjcppColorModifier &clr, const std::string &sType, const st
11591163
std::lock_guard<std::mutex> lock(WsjcppLog::g_WSJCPP_LOG_GLOBAL_CONF.logMutex);
11601164
WsjcppColorModifier def(WsjcppColorCode::FG_DEFAULT);
11611165

1162-
std::string sLogMessage = WsjcppCore::currentTime_logformat() + ", " + WsjcppCore::threadId()
1166+
std::string sLogMessage = WsjcppCore::currentTime_logformat() + ", " + WsjcppCore::getThreadId()
11631167
+ " [" + sType + "] " + sTag + ": " + sMessage;
11641168
std::cout << clr << sLogMessage << def << std::endl;
11651169

src/wsjcpp_core.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class WsjcppCore {
7878
static long currentTime_seconds();
7979
static std::string currentTime_forFilename();
8080
static std::string currentTime_logformat();
81-
static std::string threadId();
81+
static std::string getThreadId();
8282
static std::string formatTimeForWeb(long nTimeInSec);
8383
static std::string formatTimeForFilename(long nTimeInSec);
8484
static std::string formatTimeUTC(int nTimeInSec);

0 commit comments

Comments
 (0)