Brett 2023-02-08 14:12:21 -05:00
parent b4548166c3
commit f1cb6f05f5
2 changed files with 32 additions and 0 deletions

View File

@ -41,6 +41,7 @@ namespace blt::logging {
logi(str); logi(str);
} }
#endif #endif
void flush() const;
}; };
static logger tlog{TRACE}; static logger tlog{TRACE};
@ -129,6 +130,10 @@ namespace blt::logging {
void log(unsigned short i, LOG_LEVEL level, int auto_line); void log(unsigned short i, LOG_LEVEL level, int auto_line);
void log(float f, 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); 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 #ifdef BLT_DISABLE_LOGGING

View File

@ -210,6 +210,33 @@ namespace blt::logging {
thread_local_strings[id] = th_str; 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();
}
} }