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();