Add multithreaded logging infrastructure for preparation for future designs (#225)

* Update class diagrams

* Implement BoundedChannel and multithreaded logging infra

* Integrate logging channel system

* Update string concatenations to use std::format

* Add pretty print log
This commit is contained in:
2026-05-22 22:00:38 -04:00
committed by GitHub
parent 2ee7b3d2a2
commit 6a66619c70
44 changed files with 1445 additions and 439 deletions

View File

@@ -1,5 +1,5 @@
/**
* @file web_client/http_web_client.cc
* @file web_client/http_web_client.cc
* @brief cpp-httplib implementation of WebClient.
*/
@@ -7,12 +7,14 @@
#include <httplib.h>
#include <chrono>
#include <format>
#include <regex>
#include <stdexcept>
#include <string>
#include <utility>
#include "spdlog/spdlog.h"
#include "services/logging/logger.h"
namespace {
constexpr time_t kConnectionTimeoutSeconds = 5;
@@ -31,7 +33,7 @@ std::pair<std::string, std::string> SplitUrl(const std::string& url) {
return {match[1].str(), match[2].matched ? match[2].str() : "/"};
}
} // namespace
} // namespace
std::string HttpWebClient::Get(const std::string& url) {
const auto [origin, path] = SplitUrl(url);
@@ -40,24 +42,27 @@ std::string HttpWebClient::Get(const std::string& url) {
client.set_follow_location(true);
client.set_connection_timeout(kConnectionTimeoutSeconds);
client.set_read_timeout(kReadTimeoutSeconds);
client.set_default_headers({
{"Accept", "application/json"},
{"User-Agent", "biergarten-pipeline/1.0"}
});
client.set_default_headers({{"Accept", "application/json"},
{"User-Agent", "biergarten-pipeline/1.0"}});
const httplib::Result result = client.Get(path);
if (!result) {
throw std::runtime_error(
"[HttpWebClient] Request failed for URL: " + url +
"" + httplib::to_string(result.error()));
throw std::runtime_error(std::format(
"[HttpWebClient] Request failed for URL: {} — {}", url,
httplib::to_string(result.error())));
}
if (result->status < kSuccessMin || result->status >= kSuccessMax) {
spdlog::error("[HttpWebClient] Request failed for URL: " + url);
throw std::runtime_error(
"[HttpWebClient] HTTP " + std::to_string(result->status) +
" for URL: " + url);
if (logger_) {
logger_->Log(
{.level = LogLevel::Error,
.phase = PipelinePhase::UserGeneration,
.message =
std::format("[HttpWebClient] Request failed for URL: {}", url)});
}
throw std::runtime_error(std::format("[HttpWebClient] HTTP {} for URL: {}",
result->status, url));
}
return result->body;
@@ -65,4 +70,4 @@ std::string HttpWebClient::Get(const std::string& url) {
std::string HttpWebClient::EncodeURL(const std::string& value) {
return httplib::encode_uri_component(value);
}
}