21 if (lokiAddress.empty())
26 _connHandler = std::make_unique<HTTP>(lokiAddress);
29 _internalLogBuffer.push_back({
"debug", std::vector<std::pair<std::string, std::string>>()});
30 _internalLogBuffer.push_back({
"info", std::vector<std::pair<std::string, std::string>>()});
31 _internalLogBuffer.push_back({
"warn", std::vector<std::pair<std::string, std::string>>()});
32 _internalLogBuffer.push_back({
"error", std::vector<std::pair<std::string, std::string>>()});
33 _internalLogBuffer.push_back({
"critical", std::vector<std::pair<std::string, std::string>>()});
36 _basicInformation =
"";
37 _basicInformation += std::string(R
"("release_version":"v)") + PROJECT_FULL_REVISION + "\",";
38 _basicInformation += std::string(R
"("release_date":")") + PROJECT_BUILD_DATE + " " + PROJECT_BUILD_TIME +
"\",";
39 _basicInformation += std::string(R
"("compiler_name":")") + COMPILER_NAME + "\",";
40 _basicInformation += std::string(R
"("compiler_version":")") + COMPILER_VERSION + "\",";
41 _basicInformation += std::string(R
"("build":")") + BUILD_TYPE + "\",";
44 std::array<char, BUFSIZ> hostBuffer{};
45 gethostname(hostBuffer.data(), BUFSIZ);
46 _basicInformation += std::string(R
"("hostname":")") + hostBuffer.data() + "\",";
49 const std::string cpuInfoPath =
"/proc/cpuinfo";
53 _basicInformation += std::string(R
"("cpu_threadcount":")") + word + "\",";
55 _basicInformation += std::string(R
"("cpu_corecount":")") + word + "\",";
57 _basicInformation += std::string(R
"("cpu_model":")") + word + "\",";
59 _basicInformation += std::string(R
"("cpu_vendorid":")") + word + "\",";
61 _lokiAvailable =
true;
73 if (msg.level >= spdlog::level::debug && msg.level <= spdlog::level::critical)
75 _internalLogBuffer[
static_cast<size_t>(msg.level) - 1].logs.push_back(
76 {std::to_string(msg.time.time_since_epoch().count()),
77 std::string(msg.payload.data(), msg.payload.size())});
86 std::ostringstream sStream;
88 sStream <<
"{\"streams\":[";
89 for (
auto &entry : _internalLogBuffer)
91 if (entry.logs.empty())
101 sStream <<
"{\"stream\":{" << _basicInformation + R
"("level":")" << entry.level << R"("},"values":[)";
103 bool subflag =
false;
104 for (
const auto &subentry : entry.logs)
111 sStream <<
"[\"" << subentry.first <<
"\",\"" << subentry.second <<
"\"]";
122 std::string recvData;
123 HttpStatus::Code replyCode = HttpStatus::Code::xxx_max;
124 _connHandler->sendPOSTRequest(
"/loki/api/v1/push", sStream.str(), recvData, replyCode);