From 59d8b7007cbed6ba028df36a20c5ff5b257b9da6 Mon Sep 17 00:00:00 2001 From: Tomasz Golinski Date: Thu, 7 Oct 2021 14:58:52 +0200 Subject: [PATCH] Fix debug so that multithreaded output doesn't overlap (not needed here, just for consistency with other projects) --- debug.cpp | 4 ++-- debug.h | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/debug.cpp b/debug.cpp index e679b50..2cb5b74 100644 --- a/debug.cpp +++ b/debug.cpp @@ -10,7 +10,7 @@ Debug::Debug(int n) : lvl(n) { indent.append(lvl - 1, '\t'); if (lvl > 1) indent.append("*** "); - std::cerr << indent; + buffer << indent; // std::time_t now = std::time(nullptr); // std::string dt = std::ctime(&now); @@ -19,7 +19,7 @@ Debug::Debug(int n) : lvl(n) { } 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; } diff --git a/debug.h b/debug.h index a954839..8c6587c 100644 --- a/debug.h +++ b/debug.h @@ -8,6 +8,7 @@ class Debug { private: int lvl; // debug level of the particular instance of Debug stream static int debug_level; // debug level set globally + std::stringstream buffer; public: explicit Debug(int n); @@ -20,7 +21,7 @@ public: template Debug& operator<<(T const& value) { if (lvl <= debug_level) - std::cout << value; + buffer << value; return *this; } static void set_debug_level(int n);