From 0330fd7bc562f6139b42e670a063ca689c4497ce Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Mon, 27 May 2024 10:50:13 +0800 Subject: [PATCH] feat support log file template render {{date}} --- src/sled/log/log.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) 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);