feat update
Some checks failed
linux-mips64-gcc / linux-gcc-mips64el (Release) (push) Waiting to run
linux-x64-gcc / linux-gcc (Debug) (push) Waiting to run
linux-x64-gcc / linux-gcc (Release) (push) Waiting to run
linux-aarch64-cpu-gcc / linux-gcc-aarch64 (push) Failing after 45s
linux-arm-gcc / linux-gcc-armhf (push) Failing after 34s
linux-mips64-gcc / linux-gcc-mips64el (Debug) (push) Has been cancelled

This commit is contained in:
tqcq 2024-12-11 17:40:01 +08:00
parent 97681c8807
commit c06ae29c2f

View File

@ -142,12 +142,14 @@ SetLogLevel(LogLevel level)
void
SetLogFileName(const char *file_name)
{
std::ofstream tmp_stream(file_name, std::ios_base::app);
if (tmp_stream.is_open()) {
Waiter waiter(g_request_id.fetch_add(1), g_current_id);
waiter.wait();
g_log_stream.close();
g_log_file_name = file_name;
std::swap(g_log_stream, tmp_stream);
std::ofstream tmp_stream(file_name, std::ios_base::app);
g_log_stream = tmp_stream;
} else {
LOGE("log", "can't open new log file [{}]", file_name);
return;
@ -171,7 +173,10 @@ Log(LogLevel level, const char *tag, const char *fmt, const char *file_name, int
Waiter waiter(g_request_id.fetch_add(1), g_current_id);
waiter.wait();
if (g_log_stream.is_open()) { g_log_stream << msg << std::endl; }
if (g_log_stream.is_open()) {
g_log_stream << msg << std::endl;
if (waiter.id() % 100 == 99) { g_log_stream.flush(); }
}
std::cout << GetConsoleColorPrefix(level) << msg << GetConsoleColorSuffix() << std::endl;
}