|
@@ -66,6 +66,45 @@ int RvcLogSdkManager::SendTestLog(const char* body)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+int RvcLogSdkManager::SendTestLog_loki(const char* app, const char* env, const char* body)
|
|
|
+{
|
|
|
+ // 1. 构造Loki兼容的JSON请求体
|
|
|
+ Json::Value root;
|
|
|
+ Json::Value stream;
|
|
|
+ Json::Value values(Json::arrayValue);
|
|
|
+
|
|
|
+ // 设置标签
|
|
|
+ stream["app"] = app;
|
|
|
+ stream["env"] = env;
|
|
|
+
|
|
|
+ // 设置日志内容和时间戳(当前时间戳,纳秒级)
|
|
|
+ Json::Value logEntry(Json::arrayValue);
|
|
|
+ logEntry.append(std::to_string(std::chrono::duration_cast<std::chrono::nanoseconds>(
|
|
|
+ std::chrono::system_clock::now().time_since_epoch()).count()));
|
|
|
+ logEntry.append(body);
|
|
|
+ values.append(logEntry);
|
|
|
+
|
|
|
+ // 组装完整请求
|
|
|
+ Json::Value streams(Json::arrayValue);
|
|
|
+ Json::Value streamObj;
|
|
|
+ streamObj["stream"] = stream;
|
|
|
+ streamObj["values"] = values;
|
|
|
+ streams.append(streamObj);
|
|
|
+ root["streams"] = streams;
|
|
|
+
|
|
|
+ Json::FastWriter writer;
|
|
|
+ std::string jsonReq = writer.write(root);
|
|
|
+
|
|
|
+ HttpClientRequestConfig sendErr(HttpRequestMethod::POST, "http://99.12.23.49:3100/loki/api/v1/push");
|
|
|
+ HttpClientResponseResult curResult;
|
|
|
+
|
|
|
+ sendErr.SetJsonBody(jsonReq.c_str());
|
|
|
+ RestfulClient client = RestfulClient::getInstance();
|
|
|
+ sendErr.PreDo();
|
|
|
+ client.Do(&sendErr, &curResult, NULL);//Test Logs
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
|
|
|
|
|
|
#ifndef _WIN32
|