From 00788da459b4be63d087d2f66e33b8ab47651430 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Wed, 29 May 2024 11:56:34 +0800 Subject: [PATCH] feat fix daily log --- src/sled/log/log.cc | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/sled/log/log.cc b/src/sled/log/log.cc index 02f1677..ac66ee4 100644 --- a/src/sled/log/log.cc +++ b/src/sled/log/log.cc @@ -97,6 +97,18 @@ GetCurrentUTCTime() return result; } +std::string +GetLocalTime(std::string fmt = "%Y-%m-%dT%H:%M:%S") +{ + time_t rawtime; + struct tm *timeinfo; + char buffer[120]; + time(&rawtime); + timeinfo = localtime(&rawtime); + strftime(buffer, sizeof(buffer), fmt.c_str(), timeinfo); + return buffer; +} + static std::atomic g_current_id(0); static std::atomic g_request_id(0); @@ -148,12 +160,13 @@ Log(LogLevel level, const char *tag, const char *fmt, const char *file_name, int { if (level < g_log_level) { return; } - auto utc_time = GetCurrentUTCTime(); + // auto cur_time = GetCurrentUTCTime(); + auto cur_time = GetLocalTime(); auto level_str = ToShortString(level); int len = file_name ? strlen(file_name) : 0; while (len > 0 && file_name[len - 1] != '/') { len--; } - auto msg = fmt::format("{} {} {} {}:{}@{}: {}", utc_time, level_str, tag, file_name + len, line, func_name, fmt); + auto msg = fmt::format("{} {} {} {}:{}@{}: {}", cur_time, level_str, tag, file_name + len, line, func_name, fmt); Waiter waiter(g_request_id.fetch_add(1), g_current_id); waiter.wait();