diff --git a/include/spdlog/details/async_log_helper.h b/include/spdlog/details/async_log_helper.h index 4508297c..26dcac4b 100644 --- a/include/spdlog/details/async_log_helper.h +++ b/include/spdlog/details/async_log_helper.h @@ -60,7 +60,7 @@ class async_log_helper level::level_enum level; log_clock::time_point time; std::string txt; - std::thread::id thread_id; + uint64_t thread_id; async_msg() = default; ~async_msg() = default; diff --git a/include/spdlog/details/line_logger.h b/include/spdlog/details/line_logger.h index d36a251c..37c7786a 100644 --- a/include/spdlog/details/line_logger.h +++ b/include/spdlog/details/line_logger.h @@ -64,7 +64,9 @@ public: { _log_msg.logger_name = _callback_logger->name(); _log_msg.time = os::now(); - _log_msg.thread_id = std::this_thread::get_id(); + _log_msg.thread_id = os::thread_id(); + + _callback_logger->_log_msg(_log_msg); } } diff --git a/include/spdlog/details/log_msg.h b/include/spdlog/details/log_msg.h index 5c4bda30..34b5ef9a 100644 --- a/include/spdlog/details/log_msg.h +++ b/include/spdlog/details/log_msg.h @@ -46,7 +46,7 @@ struct log_msg log_msg(const log_msg& other) : logger_name(other.logger_name), - level(other.level), + level(other.level), time(other.time), thread_id(other.thread_id) { @@ -84,7 +84,7 @@ struct log_msg void clear() { - level = level::off; + level = level::off; raw.clear(); formatted.clear(); } @@ -92,7 +92,7 @@ struct log_msg std::string logger_name; level::level_enum level; log_clock::time_point time; - std::thread::id thread_id; + uint64_t thread_id; fmt::MemoryWriter raw; fmt::MemoryWriter formatted; }; diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 1fdc27b1..454bd8f5 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -32,6 +32,8 @@ # define WIN32_LEAN_AND_MEAN # endif # include +#else +#include #endif #include "../common.h" @@ -167,6 +169,17 @@ inline int utc_minutes_offset(const std::tm& tm = details::os::localtime()) } +inline uint64_t thread_id() +{ + +#ifdef _WIN32 + return ::GetCurrentThreadId(); +#else + return (uint64_t) pthread_self(); +#endif + +} + } //os } //details } //spdlog diff --git a/include/spdlog/details/pattern_formatter_impl.h b/include/spdlog/details/pattern_formatter_impl.h index 0bf2ec3a..076d76ce 100644 --- a/include/spdlog/details/pattern_formatter_impl.h +++ b/include/spdlog/details/pattern_formatter_impl.h @@ -354,7 +354,7 @@ class t_formatter :public flag_formatter { void format(details::log_msg& msg, const std::tm&) override { - msg.formatted << std::hash()(msg.thread_id); + msg.formatted << msg.thread_id; } }; @@ -478,7 +478,7 @@ inline void spdlog::pattern_formatter::handle_flag(char flag) { switch (flag) { - // logger name + // logger name case 'n': _formatters.push_back(std::unique_ptr(new details::name_formatter())); break;