Add millisecond details to debug messages timestamp

This commit is contained in:
Gioacchino Mazzurco 2020-04-05 13:00:01 +02:00
parent 76f3767756
commit 50adf00804
No known key found for this signature in database
GPG Key ID: A1FBCA3872E87051

View File

@ -75,7 +75,8 @@ private:
#else // def __ANDROID__ #else // def __ANDROID__
#include <iostream> #include <iostream>
#include <ctime> #include <chrono>
#include <iomanip>
enum class RsLoggerCategories enum class RsLoggerCategories
{ {
@ -96,8 +97,15 @@ struct t_RsLogger
template<typename T> template<typename T>
inline stream_type& operator<<(const T& val) inline stream_type& operator<<(const T& val)
{ {
return std::cerr << static_cast<char>(CATEGORY) << " " << time(nullptr) using namespace std::chrono;
<< " " << val; const auto now = system_clock::now();
const auto sec = time_point_cast<seconds>(now);
const auto msec = duration_cast<milliseconds>(now - sec);
const auto tFill = std::cerr.fill();
return std::cerr << static_cast<char>(CATEGORY) << " "
<< sec.time_since_epoch().count() << "."
<< std::setfill('0') << std::setw(3) << msec.count()
<< std::setfill(tFill) << " " << val;
} }
}; };
#endif // def __ANDROID__ #endif // def __ANDROID__