diff --git a/src/sled/log/log.cc b/src/sled/log/log.cc index f2af81d..02f1677 100644 --- a/src/sled/log/log.cc +++ b/src/sled/log/log.cc @@ -118,7 +118,7 @@ private: }; static LogLevel g_log_level = LogLevel::kTrace; -// static std::string g_log_file_name; +static std::string g_log_file_name; static std::ofstream g_log_stream; void @@ -132,12 +132,13 @@ SetLogFileName(const char *file_name) { std::ofstream tmp_stream(file_name, std::ios_base::app); if (tmp_stream.is_open()) { - // g_log_stream.open(file_name, std::ios_base::app); - // g_log_stream = std::move(tmp_stream); Waiter waiter(g_request_id.fetch_add(1), g_current_id); + waiter.wait(); + g_log_file_name = file_name; std::swap(g_log_stream, tmp_stream); } else { LOGE("log", "can't open new log file [{}]", file_name); + return; } LOGD("log", "log to new file [{}]", file_name); } @@ -156,6 +157,7 @@ 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; } std::cout << GetConsoleColorPrefix(level) << msg << GetConsoleColorSuffix() << std::endl; }