diff --git a/include/blt/std/logging.h b/include/blt/std/logging.h index a0b6dbf..be9e5d7 100644 --- a/include/blt/std/logging.h +++ b/include/blt/std/logging.h @@ -41,6 +41,7 @@ namespace blt::logging { logi(str); } #endif + void flush() const; }; static logger tlog{TRACE}; @@ -129,6 +130,10 @@ namespace blt::logging { void log(unsigned short i, LOG_LEVEL level, int auto_line); void log(float f, LOG_LEVEL level, int auto_line); void log(double f, LOG_LEVEL level, int auto_line); + /** + * Will flush all buffers! This might cause issues with threads! + */ + void flush(); } #ifdef BLT_DISABLE_LOGGING diff --git a/src/blt/std/logging.cpp b/src/blt/std/logging.cpp index 8f7a7d4..c6e29a3 100644 --- a/src/blt/std/logging.cpp +++ b/src/blt/std/logging.cpp @@ -210,6 +210,33 @@ namespace blt::logging { thread_local_strings[id] = th_str; } } + + void logger::flush() const { + for (const auto& id : thread_local_strings) { + auto th_str = id.second; + bool hasEndingLinefeed = th_str[th_str.length() - 1] == '\n'; + logging::log(th_str, false, level, !hasEndingLinefeed); + thread_local_strings[id.first] = ""; + } + } + + void flush() { + // TODO: this will prevent proper level output. Please fixme + tlog.flush(); + dlog.flush(); + ilog.flush(); + wlog.flush(); + elog.flush(); + flog.flush(); + trace.flush(); + debug.flush(); + info.flush(); + warn.flush(); + error.flush(); + fatal.flush(); + std::cerr.flush(); + std::cout.flush(); + } }