diff --git a/src/sled/log/log.cc b/src/sled/log/log.cc index 57885ee..3bd5cd9 100644 --- a/src/sled/log/log.cc +++ b/src/sled/log/log.cc @@ -98,7 +98,7 @@ GetCurrentUTCTime() } 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 @@ -110,8 +110,12 @@ SetLogLevel(LogLevel level) void SetLogFileName(const char *file_name) { - g_log_file_name = file_name; - g_log_stream.open(file_name, std::ios_base::app); + 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); + } else { + LOGE("log", "can't open new log file [{}]", file_name); + } } static std::atomic g_current_id(0);