Merge pull request #1846 from G10h4ck/millisec_dbg_message

Add millisecond details to debug messages timestamp
This commit is contained in:
csoler 2020-04-08 16:39:31 +02:00 committed by GitHub
commit b51520bccf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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__