|
|
@@ -11,6 +11,8 @@
|
|
|
#include "baseFun.h"
|
|
|
#include <chrono>
|
|
|
#include <ctime>
|
|
|
+#include <baseTime.h>
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* adjust buffer, this function will ensure tag's buffer size >= tag->now_buffer_len + new_len
|
|
|
@@ -217,24 +219,32 @@ int add_log(log_group_builder* bder, long start_time, uint32_t pack_index, log_i
|
|
|
long now;
|
|
|
char nowTime[64] = { 0 }, unitedNowTime[64] = { 0 };
|
|
|
|
|
|
- using namespace std::chrono;
|
|
|
- auto cur_now = system_clock::now();
|
|
|
- auto ms = duration_cast<milliseconds>(cur_now.time_since_epoch()) % 1000;
|
|
|
- auto timer = system_clock::to_time_t(cur_now);
|
|
|
-
|
|
|
- std::string ms_str = std::to_string(ms.count());
|
|
|
|
|
|
- // 手动补齐毫秒到3位
|
|
|
- while (ms_str.length() < 3) {
|
|
|
- ms_str = "0" + ms_str; // 或者 ms_str.insert(0, "0");
|
|
|
- }
|
|
|
+ GetCurrentTimeStr(unitedNowTime);
|
|
|
+ if (strlen(unitedNowTime) == 0)
|
|
|
+ {
|
|
|
+ using namespace std::chrono;
|
|
|
+ auto cur_now = system_clock::now();
|
|
|
+ auto ms = duration_cast<milliseconds>(cur_now.time_since_epoch()) % 1000;
|
|
|
+ auto timer = system_clock::to_time_t(cur_now);
|
|
|
+
|
|
|
+ std::string ms_str = std::to_string(ms.count());
|
|
|
|
|
|
- char buffer[20]; // 用于存储格式化后的日期和时间
|
|
|
- std::tm* local_time = std::localtime(&timer);
|
|
|
- std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", local_time); // 使用 std::strftime
|
|
|
+ // 手动补齐毫秒到3位
|
|
|
+ while (ms_str.length() < 3) {
|
|
|
+ ms_str = "0" + ms_str; // 或者 ms_str.insert(0, "0");
|
|
|
+ }
|
|
|
+
|
|
|
+ char buffer[20]; // 用于存储格式化后的日期和时间
|
|
|
+ std::tm* local_time = std::localtime(&timer);
|
|
|
+ std::strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", local_time); // 使用 std::strftime
|
|
|
+
|
|
|
+ std::ostringstream oss;
|
|
|
+ oss << buffer << '.' << ms_str;
|
|
|
+
|
|
|
+ memcpy(unitedNowTime, buffer, sizeof(buffer));
|
|
|
+ }
|
|
|
|
|
|
- std::ostringstream oss;
|
|
|
- oss << buffer << '.' << ms_str;
|
|
|
|
|
|
|
|
|
if (bder->grp->n_logs >= MAX_LOG_COUNT) {
|
|
|
@@ -245,8 +255,6 @@ int add_log(log_group_builder* bder, long start_time, uint32_t pack_index, log_i
|
|
|
get_format_uuid(bder->grp->logs[bder->grp->n_logs].uuid, MAX_UUID_LEN);
|
|
|
|
|
|
now = record_time;
|
|
|
- GetTimeStr(now, nowTime);
|
|
|
- GetUnitedTimeStr(now, unitedNowTime);
|
|
|
|
|
|
skyeye_content = cJSON_CreateObject();
|
|
|
meta_log_content = cJSON_CreateObject();
|
|
|
@@ -318,7 +326,7 @@ int add_log(log_group_builder* bder, long start_time, uint32_t pack_index, log_i
|
|
|
cJSON_AddItemToObject(log_content, "type", cJSON_CreateString("SYSTEM_PERFORMANCE"));
|
|
|
}
|
|
|
|
|
|
- cJSON_AddItemToObject(skyeye_content, "EvenTime", cJSON_CreateString(oss.str().c_str()));
|
|
|
+ cJSON_AddItemToObject(skyeye_content, "EvenTime", cJSON_CreateString(unitedNowTime));
|
|
|
if (log->BeginTime || log->EndTime)
|
|
|
{
|
|
|
cJSON_AddItemToObject(skyeye_content, "BeginTime", cJSON_CreateNumber(log->BeginTime));
|
|
|
@@ -328,7 +336,7 @@ int add_log(log_group_builder* bder, long start_time, uint32_t pack_index, log_i
|
|
|
cJSON_AddItemToObject(skyeye_content, "CostTime", cJSON_CreateNumber(log->CostTime));
|
|
|
cJSON_AddItemToObject(skyeye_content, "VtmUuid", cJSON_CreateString(bder->grp->logs[bder->grp->n_logs].uuid));
|
|
|
cJSON_AddItemToObject(skyeye_content, "Version", cJSON_CreateString(bder->config->skyeyeVersion));
|
|
|
- cJSON_AddItemToObject(skyeye_content, "DateTime", cJSON_CreateString(oss.str().c_str()));
|
|
|
+ cJSON_AddItemToObject(skyeye_content, "DateTime", cJSON_CreateString(unitedNowTime));
|
|
|
cJSON_AddItemToObject(skyeye_content, "ResultCode", cJSON_CreateString(log->ResultCode));
|
|
|
|
|
|
//迁移到公共位置,都需要这个数�?
|
|
|
@@ -399,7 +407,7 @@ int add_log(log_group_builder* bder, long start_time, uint32_t pack_index, log_i
|
|
|
|
|
|
|
|
|
|
|
|
- cJSON_AddItemToObject(united_content, "ts", cJSON_CreateString(oss.str().c_str()));
|
|
|
+ cJSON_AddItemToObject(united_content, "ts", cJSON_CreateString(unitedNowTime));
|
|
|
|
|
|
cJSON_AddItemToObject(simpleLog_content, "content", skyeye_content);
|
|
|
cJSON_AddItemToObject(united_content, "log", simpleLog_content);
|