mirror of
https://github.com/gabime/spdlog.git
synced 2025-01-06 15:04:49 +08:00
use size_t to better represent thread id across platforms
This commit is contained in:
parent
7105fdadf9
commit
0684b4f378
@ -59,6 +59,7 @@ using log_clock = std::chrono::system_clock;
|
|||||||
using sink_ptr = std::shared_ptr < sinks::sink > ;
|
using sink_ptr = std::shared_ptr < sinks::sink > ;
|
||||||
using sinks_init_list = std::initializer_list < sink_ptr > ;
|
using sinks_init_list = std::initializer_list < sink_ptr > ;
|
||||||
using formatter_ptr = std::shared_ptr<spdlog::formatter>;
|
using formatter_ptr = std::shared_ptr<spdlog::formatter>;
|
||||||
|
using thread_id = std::size_t;
|
||||||
|
|
||||||
//Log level enum
|
//Log level enum
|
||||||
namespace level
|
namespace level
|
||||||
|
@ -59,7 +59,7 @@ class async_log_helper
|
|||||||
std::string logger_name;
|
std::string logger_name;
|
||||||
level::level_enum level;
|
level::level_enum level;
|
||||||
log_clock::time_point time;
|
log_clock::time_point time;
|
||||||
uint64_t thread_id;
|
thread_id thread_id;
|
||||||
std::string txt;
|
std::string txt;
|
||||||
|
|
||||||
async_msg() = default;
|
async_msg() = default;
|
||||||
@ -77,7 +77,7 @@ async_msg(async_msg&& other) SPDLOG_NOEXCEPT:
|
|||||||
logger_name = std::move(other.logger_name);
|
logger_name = std::move(other.logger_name);
|
||||||
level = other.level;
|
level = other.level;
|
||||||
time = std::move(other.time);
|
time = std::move(other.time);
|
||||||
thread_id = other.thread_id;
|
thread_id = other.thread_id;
|
||||||
txt = std::move(other.txt);
|
txt = std::move(other.txt);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@ -90,7 +90,7 @@ async_msg(async_msg&& other) SPDLOG_NOEXCEPT:
|
|||||||
logger_name(m.logger_name),
|
logger_name(m.logger_name),
|
||||||
level(m.level),
|
level(m.level),
|
||||||
time(m.time),
|
time(m.time),
|
||||||
thread_id(m.thread_id),
|
thread_id(m.thread_id),
|
||||||
txt(m.raw.data(), m.raw.size())
|
txt(m.raw.data(), m.raw.size())
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ struct log_msg
|
|||||||
std::string logger_name;
|
std::string logger_name;
|
||||||
level::level_enum level;
|
level::level_enum level;
|
||||||
log_clock::time_point time;
|
log_clock::time_point time;
|
||||||
uint64_t thread_id;
|
thread_id thread_id;
|
||||||
fmt::MemoryWriter raw;
|
fmt::MemoryWriter raw;
|
||||||
fmt::MemoryWriter formatted;
|
fmt::MemoryWriter formatted;
|
||||||
};
|
};
|
||||||
|
@ -32,11 +32,11 @@
|
|||||||
# define WIN32_LEAN_AND_MEAN
|
# define WIN32_LEAN_AND_MEAN
|
||||||
# endif
|
# endif
|
||||||
# include <Windows.h>
|
# include <Windows.h>
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
|
#include <sys/syscall.h> //Use gettid() syscall under linux to get thread id
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#else
|
#else
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "../common.h"
|
#include "../common.h"
|
||||||
@ -172,14 +172,14 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime())
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Return current thread id as 64 bit integer
|
//Return current thread id as 64 bit integer
|
||||||
inline uint64_t thread_id()
|
inline size_t thread_id()
|
||||||
{
|
{
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
return ::GetCurrentThreadId();
|
return ::GetCurrentThreadId();
|
||||||
#elif __linux__
|
#elif __linux__
|
||||||
return (uint64_t) syscall(SYS_gettid);
|
return (uint64_t) syscall(SYS_gettid);
|
||||||
#else
|
#else
|
||||||
return (uint64_t) pthread_self();
|
return (uint64_t) pthread_self();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user