mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-06-01 01:54:00 +00:00
Integrate logging channel system
update logging to use logger channel updates
This commit is contained in:
@@ -2,8 +2,6 @@
|
||||
* @file wikipedia/fetch_extract.cc
|
||||
*/
|
||||
|
||||
#include <spdlog/spdlog.h>
|
||||
|
||||
#include <boost/json.hpp>
|
||||
#include <chrono>
|
||||
#include <format>
|
||||
@@ -22,7 +20,10 @@ std::string WikipediaEnrichmentService::FetchExtract(std::string_view query) {
|
||||
// 1. Cache Lookup
|
||||
if (const auto cache_it = this->extract_cache_.find(cache_key);
|
||||
cache_it != this->extract_cache_.end()) {
|
||||
spdlog::debug("Wikipedia: Cache hit for {}!", cache_key);
|
||||
if (logger_) {
|
||||
logger_->Log(LogLevel::Debug, PipelinePhase::UserGeneration,
|
||||
std::string("Wikipedia: Cache hit for ") + cache_key + "!");
|
||||
}
|
||||
return cache_it->second;
|
||||
}
|
||||
|
||||
@@ -44,15 +45,22 @@ std::string WikipediaEnrichmentService::FetchExtract(std::string_view query) {
|
||||
json::value doc = json::parse(body, ec);
|
||||
|
||||
if (ec) {
|
||||
spdlog::warn("WikipediaService: JSON parse error for '{}': {}", query,
|
||||
ec.message());
|
||||
if (logger_) {
|
||||
logger_->Log(LogLevel::Warn, PipelinePhase::UserGeneration,
|
||||
std::string("WikipediaService: JSON parse error for '") +
|
||||
std::string(query) + "': " + ec.message());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
// 3. Safe Extraction
|
||||
const json::object* obj = doc.if_object();
|
||||
if (obj == nullptr) {
|
||||
spdlog::warn("WikipediaService: Expected root object for '{}'", query);
|
||||
if (logger_) {
|
||||
logger_->Log(LogLevel::Warn, PipelinePhase::UserGeneration,
|
||||
std::string("WikipediaService: Expected root object for '") +
|
||||
std::string(query) + "'");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -63,14 +71,22 @@ std::string WikipediaEnrichmentService::FetchExtract(std::string_view query) {
|
||||
: nullptr;
|
||||
|
||||
if ((pages_ptr == nullptr) || !pages_ptr->is_object()) {
|
||||
spdlog::warn("WikipediaService: Missing query.pages for '{}'", query);
|
||||
if (logger_) {
|
||||
logger_->Log(LogLevel::Warn, PipelinePhase::UserGeneration,
|
||||
std::string("WikipediaService: Missing query.pages for '") +
|
||||
std::string(query) + "'");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
const json::object& pages = pages_ptr->get_object();
|
||||
|
||||
if (pages.empty()) {
|
||||
spdlog::warn("WikipediaService: No pages returned for '{}'", query);
|
||||
if (logger_) {
|
||||
logger_->Log(LogLevel::Warn, PipelinePhase::UserGeneration,
|
||||
std::string("WikipediaService: No pages returned for '") +
|
||||
std::string(query) + "'");
|
||||
}
|
||||
this->extract_cache_.emplace(cache_key, "");
|
||||
return {};
|
||||
}
|
||||
@@ -80,7 +96,11 @@ std::string WikipediaEnrichmentService::FetchExtract(std::string_view query) {
|
||||
const json::value& page_val = pages.begin()->value();
|
||||
|
||||
if (!page_val.is_object()) {
|
||||
spdlog::warn("WikipediaService: Unexpected page format for '{}'", query);
|
||||
if (logger_) {
|
||||
logger_->Log(LogLevel::Warn, PipelinePhase::UserGeneration,
|
||||
std::string("WikipediaService: Unexpected page format for '") +
|
||||
std::string(query) + "'");
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -88,7 +108,11 @@ std::string WikipediaEnrichmentService::FetchExtract(std::string_view query) {
|
||||
|
||||
// Handle 404/Missing status
|
||||
if (page.contains("missing")) {
|
||||
spdlog::warn("WikipediaService: Page '{}' does not exist", query);
|
||||
if (logger_) {
|
||||
logger_->Log(LogLevel::Warn, PipelinePhase::UserGeneration,
|
||||
std::string("WikipediaService: Page '") + std::string(query) +
|
||||
"' does not exist");
|
||||
}
|
||||
this->extract_cache_.emplace(cache_key, "");
|
||||
return {};
|
||||
}
|
||||
@@ -96,15 +120,23 @@ std::string WikipediaEnrichmentService::FetchExtract(std::string_view query) {
|
||||
const json::value* extract_ptr = page.if_contains("extract");
|
||||
|
||||
if ((extract_ptr == nullptr) || !extract_ptr->is_string()) {
|
||||
spdlog::warn("WikipediaService: No extract string found for '{}'", query);
|
||||
if (logger_) {
|
||||
logger_->Log(LogLevel::Warn, PipelinePhase::UserGeneration,
|
||||
std::string("WikipediaService: No extract string found for '") +
|
||||
std::string(query) + "'");
|
||||
}
|
||||
this->extract_cache_.emplace(cache_key, "");
|
||||
return {};
|
||||
}
|
||||
|
||||
// 4. Success
|
||||
std::string extract(extract_ptr->as_string());
|
||||
spdlog::info("WikipediaService: Fetched {} chars for '{}'", extract.size(),
|
||||
query);
|
||||
if (logger_) {
|
||||
logger_->Log(LogLevel::Info, PipelinePhase::UserGeneration,
|
||||
std::string("WikipediaService: Fetched ") +
|
||||
std::to_string(extract.size()) + " chars for '" +
|
||||
std::string(query) + "'");
|
||||
}
|
||||
|
||||
this->extract_cache_.insert_or_assign(cache_key, extract);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user