Added threadID in case someone wants that. The std:🧵:id is looong. cutting it down would be nice,. but that is a job for the client

This commit is contained in:
KjellKod 2014-05-25 01:38:03 -06:00
parent 9be8f49f66
commit 98ec05db7b
2 changed files with 18 additions and 1 deletions

View File

@ -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)
@ -111,6 +117,13 @@ namespace g2 {
, _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) { }

View File

@ -15,6 +15,7 @@
#include <string>
#include <sstream>
#include <chrono>
#include <thread>
#include "g2loglevels.hpp"
#include "g2time.hpp"
@ -48,6 +49,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;