From 98ec05db7b056403bba744ee22136ff1f69fefc9 Mon Sep 17 00:00:00 2001 From: KjellKod Date: Sun, 25 May 2014 01:38:03 -0600 Subject: [PATCH] Added threadID in case someone wants that. The std::thread::id is looong. cutting it down would be nice,. but that is a job for the client --- g2log/src/g2logmessage.cpp | 15 ++++++++++++++- g2log/src/g2logmessage.hpp | 4 ++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/g2log/src/g2logmessage.cpp b/g2log/src/g2logmessage.cpp index 2107d3d..6695507 100644 --- a/g2log/src/g2logmessage.cpp +++ b/g2log/src/g2logmessage.cpp @@ -77,8 +77,12 @@ namespace g2 { LogMessage::LogMessage(const std::string &file, const int line, const std::string& function, const LEVELS& level) : _timestamp(g2::systemtime_now()) + , _call_thread_id(std::this_thread::get_id()) , _microseconds(microsecondsCounter()) - , _file(splitFileName(file)), _line(line), _function(function), _level(level) + , _file(splitFileName(file)) + , _line(line) + , _function(function) + , _level(level) {} @@ -89,6 +93,7 @@ namespace g2 { LogMessage::LogMessage(const LogMessage& other) : _timestamp(other._timestamp) + , _call_thread_id(other._call_thread_id) , _microseconds(other._microseconds) , _file(other._file) , _line(other._line) @@ -102,6 +107,7 @@ namespace g2 { LogMessage::LogMessage(LogMessage&& other) : _timestamp(other._timestamp) + , _call_thread_id(other._call_thread_id) , _microseconds(other._microseconds) , _file(std::move(other._file)) , _line(other._line) @@ -110,6 +116,13 @@ namespace g2 { , _expression(std::move(other._expression)) , _message(std::move(other._message)) { } + + + std::string LogMessage::threadID() const { + std::ostringstream oss; + oss << _call_thread_id; + return oss.str(); + } FatalMessage::FatalMessage(const LogMessage& details, int signal_id) : LogMessage(details), _signal_id(signal_id) { } diff --git a/g2log/src/g2logmessage.hpp b/g2log/src/g2logmessage.hpp index 0d23688..44b75fb 100644 --- a/g2log/src/g2logmessage.hpp +++ b/g2log/src/g2logmessage.hpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "g2loglevels.hpp" #include "g2time.hpp" @@ -47,6 +48,8 @@ namespace g2 { std::string expression() const { return _expression; } bool wasFatal() const { return internal::wasFatal(_level); } + + std::string threadID() const; std::string toString() const; void setExpression(const std::string expression) { _expression = expression; } @@ -64,6 +67,7 @@ namespace g2 { // are not enough. // std::time_t _timestamp; + std::thread::id _call_thread_id; int64_t _microseconds; std::string _file; int _line;