Fix debug so that multithreaded output doesn't overlap (not needed here, just for consistency with other projects)

master
Tomasz Golinski 2021-10-07 14:58:52 +02:00
rodzic dcaa8fbf71
commit 59d8b7007c
2 zmienionych plików z 4 dodań i 3 usunięć

Wyświetl plik

@ -10,7 +10,7 @@ Debug::Debug(int n) : lvl(n) {
indent.append(lvl - 1, '\t'); indent.append(lvl - 1, '\t');
if (lvl > 1) indent.append("*** "); if (lvl > 1) indent.append("*** ");
std::cerr << indent; buffer << indent;
// std::time_t now = std::time(nullptr); // std::time_t now = std::time(nullptr);
// std::string dt = std::ctime(&now); // std::string dt = std::ctime(&now);
@ -19,7 +19,7 @@ Debug::Debug(int n) : lvl(n) {
} }
Debug::~Debug() { Debug::~Debug() {
if (lvl <= debug_level) std::cerr << '\n'; if (lvl <= debug_level) std::cerr << buffer.str() << '\n';
} }
void Debug::set_debug_level(int n) { debug_level = n; } void Debug::set_debug_level(int n) { debug_level = n; }

Wyświetl plik

@ -8,6 +8,7 @@ class Debug {
private: private:
int lvl; // debug level of the particular instance of Debug stream int lvl; // debug level of the particular instance of Debug stream
static int debug_level; // debug level set globally static int debug_level; // debug level set globally
std::stringstream buffer;
public: public:
explicit Debug(int n); explicit Debug(int n);
@ -20,7 +21,7 @@ public:
template <typename T> template <typename T>
Debug& operator<<(T const& value) { Debug& operator<<(T const& value) {
if (lvl <= debug_level) if (lvl <= debug_level)
std::cout << value; buffer << value;
return *this; return *this;
} }
static void set_debug_level(int n); static void set_debug_level(int n);