Route all logging through the Void::Log facade

Delete the echoion Logger adapter (Logger.{hpp,cpp}) and the
ILogger/LoggerRegistry indirection. Core::installLogging() builds the
console + split-file Void::Logging::MultiLogger and installs it as the
process-wide Void::Log sink via Void::Log::make_sink (logSink_ owns it for
the process lifetime). The ~450 ECHOION_LOG_* call sites across EchoionCore
are rewritten to Void::Log::<level>("<Subsystem>", "{}", <expr>) with
per-file module tags (warning->warn, critical->fatal); the pre-formatted
message is passed as the single "{}" argument. Build green.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Opus 4.8 committed 2026-06-23 14:10:06 +03:00
1 parent 0e08ccaefa
commit 2d7651c308
42 files changed
+550 -792

No files matched your search

+66 -67
View File
@@ -1,6 +1,5 @@
#include "echoion/core/Logger.hpp"
#include <Void/Log/Log.hpp>
#include "echoion/core/YouTubeClient.hpp"
#include <LoggerInterface.hpp>
#include <Void/Data/Json.hpp>
#include <Void/Text/Html.hpp>
#include <Void/Text/Url.hpp>
@@ -41,7 +40,7 @@ namespace Echoion::Core
return {};
}
ECHOION_LOG_INFO("Initializing YouTube client...");
Void::Log::info("YouTubeClient", "{}", "Initializing YouTube client...");
// Initialize yt-dlp manager (downloads if needed)
auto result = ytDlpManager_->initialize();
@@ -53,7 +52,7 @@ namespace Echoion::Core
ytDlpManager_->setThreadPoolSize(maxConcurrentResolutions_);
initialized_ = true;
ECHOION_LOG_INFO("YouTube client initialized successfully");
Void::Log::info("YouTubeClient", "{}", "YouTube client initialized successfully");
return {};
}
@@ -80,7 +79,7 @@ namespace Echoion::Core
std::lock_guard<std::mutex> lock(configMutex_);
if (proxy.has_value() && proxy->enabled()) {
ECHOION_LOG_INFO(
Void::Log::info("YouTubeClient", "{}",
std::format("YouTubeClient proxy configured: {}:{}",
proxy->host, proxy->port));
}
@@ -98,7 +97,7 @@ namespace Echoion::Core
{
std::lock_guard<std::mutex> lock(configMutex_);
apiKey_ = apiKey;
ECHOION_LOG_INFO(
Void::Log::info("YouTubeClient", "{}",
"YouTube API key configured for enhanced playlist resolution");
}
@@ -174,7 +173,7 @@ namespace Echoion::Core
}
auto startTime = std::chrono::steady_clock::now();
ECHOION_LOG_INFO(
Void::Log::info("YouTubeClient", "{}",
std::format("Getting audio stream URL for video: {}", videoId));
// Use yt-dlp to get best audio URL - prefer AAC (m4a) over Opus (webm)
@@ -182,16 +181,16 @@ namespace Echoion::Core
// Pass just the video ID to yt-dlp
std::string videoIdStr(videoId);
ECHOION_LOG_DEBUG("Starting yt-dlp audio URL extraction...");
Void::Log::debug("YouTubeClient", "{}", "Starting yt-dlp audio URL extraction...");
auto future = ytDlpManager_->executeAsync(
{videoIdStr, "-f", "bestaudio/251/140", "-g", "--no-warnings"});
// Wait with timeout (30 seconds)
ECHOION_LOG_DEBUG("Waiting for yt-dlp audio URL (30s timeout)...");
Void::Log::debug("YouTubeClient", "{}", "Waiting for yt-dlp audio URL (30s timeout)...");
auto waitStatus = future.wait_for(std::chrono::seconds(30));
if (waitStatus == std::future_status::timeout) {
ECHOION_LOG_WARNING(
Void::Log::warn("YouTubeClient", "{}",
"yt-dlp audio URL extraction timed out after 30s");
return Api::fail(Api::ErrorCode::NetworkError,
"yt-dlp audio URL extraction timed out");
@@ -200,7 +199,7 @@ namespace Echoion::Core
auto ytdlpResult = future.get();
if (!ytdlpResult.success) {
ECHOION_LOG_WARNING("yt-dlp audio URL extraction failed");
Void::Log::warn("YouTubeClient", "{}", "yt-dlp audio URL extraction failed");
return Api::fail(Api::ErrorCode::NetworkError,
"yt-dlp audio URL extraction failed");
}
@@ -216,12 +215,12 @@ namespace Echoion::Core
.count();
if (!result.empty() && result.find("http") == 0) {
ECHOION_LOG_INFO(std::format(
Void::Log::info("YouTubeClient", "{}", std::format(
"Successfully got audio URL from yt-dlp in {} ms", elapsed));
return result;
}
ECHOION_LOG_WARNING(std::format(
Void::Log::warn("YouTubeClient", "{}", std::format(
"Failed to get audio URL from yt-dlp after {} ms", elapsed));
return Api::fail(
Api::ErrorCode::NotFound, "Failed to get audio URL from yt-dlp");
@@ -252,7 +251,7 @@ namespace Echoion::Core
"Video ID is empty");
}
ECHOION_LOG_DEBUG(
Void::Log::debug("YouTubeClient", "{}",
std::format("Getting video info for ID: '{}'", videoId));
auto infoStart = std::chrono::steady_clock::now();
@@ -262,18 +261,18 @@ namespace Echoion::Core
ytDlpManager_->executeAsync({videoIdStr, "-J", "--no-warnings"});
// Wait with timeout (30 seconds)
ECHOION_LOG_DEBUG("Waiting for yt-dlp video info (30s timeout)...");
Void::Log::debug("YouTubeClient", "{}", "Waiting for yt-dlp video info (30s timeout)...");
auto waitStatus = result.wait_for(std::chrono::seconds(30));
if (waitStatus == std::future_status::timeout) {
ECHOION_LOG_WARNING("yt-dlp video info timed out after 30s");
Void::Log::warn("YouTubeClient", "{}", "yt-dlp video info timed out after 30s");
return Api::fail(Api::ErrorCode::NetworkError,
"yt-dlp video info timed out");
}
auto ytdlpResult = result.get();
ECHOION_LOG_DEBUG(
Void::Log::debug("YouTubeClient", "{}",
std::format("yt-dlp video info completed in {} ms",
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - infoStart)
@@ -366,17 +365,17 @@ namespace Echoion::Core
// Use YouTube Data API v3 if key is available
if (hasApiKey()) {
ECHOION_LOG_INFO(
Void::Log::info("YouTubeClient", "{}",
std::format("Searching YouTube via API: '{}'", query));
result = searchWithApi(query, pageToken);
} else {
// Fallback to yt-dlp if no API key
ECHOION_LOG_WARNING("No YouTube API key configured, falling back "
Void::Log::warn("YouTubeClient", "{}", "No YouTube API key configured, falling back "
"to yt-dlp for search");
result = searchWithYtDlp(query, pageToken);
}
ECHOION_LOG_INFO(
Void::Log::info("YouTubeClient", "{}",
std::format("YouTube search took {} ms",
std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - startTime)
@@ -409,7 +408,7 @@ namespace Echoion::Core
}
// Execute with timeout (10 seconds for API search)
ECHOION_LOG_DEBUG("Executing YouTube API search with 10s timeout...");
Void::Log::debug("YouTubeClient", "{}", "Executing YouTube API search with 10s timeout...");
// Use shared promise so detached thread can safely complete
auto responsePromise =
@@ -419,36 +418,36 @@ namespace Echoion::Core
std::thread apiThread(
[this, url = std::string(url), responsePromise]() {
ECHOION_LOG_DEBUG("API request thread started");
Void::Log::debug("YouTubeClient", "{}", "API request thread started");
try {
auto result = networkClient_->get(url);
responsePromise->set_value(std::move(result));
} catch (...) {
responsePromise->set_exception(std::current_exception());
}
ECHOION_LOG_DEBUG("API request thread completed");
Void::Log::debug("YouTubeClient", "{}", "API request thread completed");
});
// Wait with timeout
auto waitStatus = responseFuture.wait_for(std::chrono::seconds(10));
if (waitStatus == std::future_status::timeout) {
ECHOION_LOG_WARNING("YouTube API search timed out after 10s");
Void::Log::warn("YouTubeClient", "{}", "YouTube API search timed out after 10s");
apiThread.detach(); // Thread owns shared_ptr, safe to detach
return Api::fail(Api::ErrorCode::NetworkError,
"YouTube API search timed out");
}
ECHOION_LOG_DEBUG("Joining API request thread...");
Void::Log::debug("YouTubeClient", "{}", "Joining API request thread...");
apiThread.join();
ECHOION_LOG_DEBUG("API request thread joined");
Void::Log::debug("YouTubeClient", "{}", "API request thread joined");
// Get the response
Api::Result<Void::Net::Response> response;
try {
response = responseFuture.get();
} catch (const std::exception& e) {
ECHOION_LOG_ERROR(
Void::Log::error("YouTubeClient", "{}",
std::format("API request threw exception: {}", e.what()));
return Api::fail(Api::ErrorCode::NetworkError,
std::format("API request failed: {}", e.what()));
@@ -456,10 +455,10 @@ namespace Echoion::Core
// Log response status
if (response) {
ECHOION_LOG_DEBUG(
Void::Log::debug("YouTubeClient", "{}",
std::format("API response status: {}", response->status));
} else {
ECHOION_LOG_WARNING(std::format("API request failed: {}",
Void::Log::warn("YouTubeClient", "{}", std::format("API request failed: {}",
response.error().message));
}
@@ -544,23 +543,23 @@ namespace Echoion::Core
// Fetch duration for each video using videos endpoint (batch
// request)
if (!videoIds.empty()) {
ECHOION_LOG_DEBUG("Fetching video durations...");
Void::Log::debug("YouTubeClient", "{}", "Fetching video durations...");
fetchVideoDurations(result.tracks, videoIds);
ECHOION_LOG_DEBUG("Video durations fetched");
Void::Log::debug("YouTubeClient", "{}", "Video durations fetched");
}
}
ECHOION_LOG_INFO(
Void::Log::info("YouTubeClient", "{}",
std::format("YouTube API search returned {} results",
result.tracks.size()));
// Populate shortened URLs for all tracks (already non-blocking with
// timeout)
ECHOION_LOG_DEBUG("Populating shortened URLs...");
Void::Log::debug("YouTubeClient", "{}", "Populating shortened URLs...");
populateShortenedUrls(result.tracks);
ECHOION_LOG_DEBUG("Shortened URLs populated");
Void::Log::debug("YouTubeClient", "{}", "Shortened URLs populated");
ECHOION_LOG_DEBUG("Returning search result");
Void::Log::debug("YouTubeClient", "{}", "Returning search result");
return result;
} catch (const std::exception& e) {
@@ -617,7 +616,7 @@ namespace Echoion::Core
auto waitStatus = responseFuture.wait_for(std::chrono::seconds(5));
if (waitStatus == std::future_status::timeout) {
ECHOION_LOG_WARNING("Video duration fetch timed out after 5s");
Void::Log::warn("YouTubeClient", "{}", "Video duration fetch timed out after 5s");
durationThread.detach();
return;
}
@@ -628,13 +627,13 @@ namespace Echoion::Core
try {
response = responseFuture.get();
} catch (const std::exception& e) {
ECHOION_LOG_WARNING(
Void::Log::warn("YouTubeClient", "{}",
std::format("Video duration request failed: {}", e.what()));
return;
}
if (!response || !response->ok()) {
ECHOION_LOG_WARNING(
Void::Log::warn("YouTubeClient", "{}",
"Failed to fetch video durations from YouTube API");
return;
}
@@ -664,7 +663,7 @@ namespace Echoion::Core
(*contentDetails).get_str("duration");
auto duration = Void::Time::parse_iso8601_interval(durationStr).value_or(std::chrono::seconds{0});
if (duration.count() > 0) {
ECHOION_LOG_DEBUG(
Void::Log::debug("YouTubeClient", "{}",
std::format("Got duration: {}, parse as: {}",
durationStr, duration));
durationMap[videoId] = duration;
@@ -684,7 +683,7 @@ namespace Echoion::Core
}
} catch (const std::exception& e) {
ECHOION_LOG_WARNING(
Void::Log::warn("YouTubeClient", "{}",
std::format("Failed to parse video durations: {}", e.what()));
}
}
@@ -698,7 +697,7 @@ namespace Echoion::Core
Api::ErrorCode::ServiceUnavailable, "yt-dlp not available");
}
ECHOION_LOG_DEBUG("Starting yt-dlp search...");
Void::Log::debug("YouTubeClient", "{}", "Starting yt-dlp search...");
auto searchStart = std::chrono::steady_clock::now();
// yt-dlp search format: ytsearch5:query
@@ -708,11 +707,11 @@ namespace Echoion::Core
{searchQuery, "-J", "--flat-playlist", "--no-warnings"});
// Wait with timeout (30 seconds for yt-dlp search)
ECHOION_LOG_DEBUG("Waiting for yt-dlp search result (30s timeout)...");
Void::Log::debug("YouTubeClient", "{}", "Waiting for yt-dlp search result (30s timeout)...");
auto waitStatus = result.wait_for(std::chrono::seconds(30));
if (waitStatus == std::future_status::timeout) {
ECHOION_LOG_WARNING("yt-dlp search timed out after 30s");
Void::Log::warn("YouTubeClient", "{}", "yt-dlp search timed out after 30s");
return Api::fail(Api::ErrorCode::NetworkError,
"yt-dlp search timed out");
}
@@ -722,7 +721,7 @@ namespace Echoion::Core
auto elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::steady_clock::now() - searchStart)
.count();
ECHOION_LOG_DEBUG(
Void::Log::debug("YouTubeClient", "{}",
std::format("yt-dlp search completed in {} ms", elapsed));
if (!ytdlpResult.success || ytdlpResult.output.empty()) {
@@ -798,7 +797,7 @@ namespace Echoion::Core
"YouTubeClient not initialized");
}
ECHOION_LOG_INFO(std::format("Fetching playlist: {}", playlistId));
Void::Log::info("YouTubeClient", "{}", std::format("Fetching playlist: {}", playlistId));
// Step 1: Fetch playlist items (via API v2 if key available, else
// yt-dlp)
@@ -815,7 +814,7 @@ namespace Echoion::Core
return emptyInfo;
}
ECHOION_LOG_INFO(std::format(
Void::Log::info("YouTubeClient", "{}", std::format(
"Found {} tracks in playlist, resolving individually...",
items.size()));
@@ -850,12 +849,12 @@ namespace Echoion::Core
if (result) {
resolvedTracks.push_back(std::move(*result));
} else {
ECHOION_LOG_WARNING(std::format(
Void::Log::warn("YouTubeClient", "{}", std::format(
"Failed to resolve track: {}", result.error().message));
}
}
ECHOION_LOG_DEBUG(std::format(
Void::Log::debug("YouTubeClient", "{}", std::format(
"Resolved batch {}/{} ({} tracks so far)", (i / batchSize) + 1,
(items.size() + batchSize - 1) / batchSize,
resolvedTracks.size()));
@@ -870,7 +869,7 @@ namespace Echoion::Core
info.name = std::format("Playlist ({} tracks)", info.tracks.size());
}
ECHOION_LOG_INFO(
Void::Log::info("YouTubeClient", "{}",
std::format("Successfully resolved {}/{} tracks from playlist",
info.tracks.size(), items.size()));
@@ -904,12 +903,12 @@ namespace Echoion::Core
return;
}
ECHOION_LOG_INFO(std::format("Streaming playlist: {}", playlistId));
Void::Log::info("YouTubeClient", "{}", std::format("Streaming playlist: {}", playlistId));
// Fetch playlist items first (quick operation)
auto itemsResult = fetchPlaylistItems(playlistId);
if (!itemsResult || itemsResult->empty()) {
ECHOION_LOG_WARNING("No items found in playlist or fetch failed");
Void::Log::warn("YouTubeClient", "{}", "No items found in playlist or fetch failed");
if (onComplete) {
onComplete();
}
@@ -917,7 +916,7 @@ namespace Echoion::Core
}
const auto& items = *itemsResult;
ECHOION_LOG_INFO(
Void::Log::info("YouTubeClient", "{}",
std::format("Streaming {} tracks from playlist", items.size()));
// Notify about total tracks
@@ -955,17 +954,17 @@ namespace Echoion::Core
// start
trackCallback(std::move(*result));
} else {
ECHOION_LOG_WARNING(std::format(
Void::Log::warn("YouTubeClient", "{}", std::format(
"Failed to resolve track: {}", result.error().message));
}
}
ECHOION_LOG_DEBUG(
Void::Log::debug("YouTubeClient", "{}",
std::format("Processed batch {}/{}", (i / batchSize) + 1,
(items.size() + batchSize - 1) / batchSize));
}
ECHOION_LOG_INFO("Playlist streaming complete");
Void::Log::info("YouTubeClient", "{}", "Playlist streaming complete");
if (onComplete) {
onComplete();
}
@@ -979,7 +978,7 @@ namespace Echoion::Core
// Try using YouTube Data API v3 if key is available
if (hasApiKey()) {
ECHOION_LOG_INFO("Using YouTube Data API v3 for playlist fetch");
Void::Log::info("YouTubeClient", "{}", "Using YouTube Data API v3 for playlist fetch");
std::optional<std::string> pageToken;
do {
@@ -987,7 +986,7 @@ namespace Echoion::Core
auto response = networkClient_->get(apiUrl);
if (!response || !response->ok()) {
ECHOION_LOG_WARNING(
Void::Log::warn("YouTubeClient", "{}",
"YouTube API request failed, falling back to yt-dlp");
break; // Fall back to yt-dlp
}
@@ -995,7 +994,7 @@ namespace Echoion::Core
try {
auto parsed = Void::Json::parse(response->body);
if (!parsed) {
ECHOION_LOG_WARNING(
Void::Log::warn("YouTubeClient", "{}",
"Failed to parse YouTube API response, "
"falling back to yt-dlp");
break;
@@ -1049,21 +1048,21 @@ namespace Echoion::Core
}
} catch (const std::exception& e) {
ECHOION_LOG_WARNING(std::format(
Void::Log::warn("YouTubeClient", "{}", std::format(
"Error parsing YouTube API response: {}", e.what()));
break; // Fall back to yt-dlp
}
} while (pageToken.has_value());
if (!items.empty()) {
ECHOION_LOG_INFO(std::format(
Void::Log::info("YouTubeClient", "{}", std::format(
"Fetched {} tracks via YouTube API", items.size()));
return items;
}
}
// Fallback: Use yt-dlp to fetch playlist items
ECHOION_LOG_INFO("Using yt-dlp for playlist fetch");
Void::Log::info("YouTubeClient", "{}", "Using yt-dlp for playlist fetch");
if (!ytDlpManager_->isAvailable()) {
return Api::fail(
@@ -1114,7 +1113,7 @@ namespace Echoion::Core
}
}
ECHOION_LOG_INFO(
Void::Log::info("YouTubeClient", "{}",
std::format("Fetched {} tracks via yt-dlp", items.size()));
return items;
@@ -1232,7 +1231,7 @@ namespace Echoion::Core
// Handle faumaray.ru redirects using NetworkClient
if (url_str.find("faumaray.ru") != std::string::npos &&
networkClient_) {
ECHOION_LOG_DEBUG(
Void::Log::debug("YouTubeClient", "{}",
std::format("Following redirect for: {}", url_str));
std::vector<Void::Net::Header> headers = {
@@ -1248,7 +1247,7 @@ namespace Echoion::Core
if (response->status >= 300 && response->status < 400) {
auto location = response->header("location");
if (location.has_value()) {
ECHOION_LOG_DEBUG(
Void::Log::debug("YouTubeClient", "{}",
std::format("Redirected to: {}", *location));
url_str = std::string(*location);
}
@@ -1323,7 +1322,7 @@ namespace Echoion::Core
{
std::lock_guard<std::mutex> lock(configMutex_);
urlShorteningEnabled_ = enabled;
ECHOION_LOG_INFO(
Void::Log::info("YouTubeClient", "{}",
std::format("URL shortening {}", enabled ? "enabled" : "disabled"));
}
@@ -1378,13 +1377,13 @@ namespace Echoion::Core
}
if (shortenedUrl->has_value()) {
track.shortenedUrl = *shortenedUrl;
ECHOION_LOG_DEBUG(std::format("URL shortened for {}: {}",
Void::Log::debug("YouTubeClient", "{}", std::format("URL shortened for {}: {}",
track.title,
track.shortenedUrl.value()));
}
} else {
// Timeout - thread owns shared_ptr, safe to detach
ECHOION_LOG_WARNING(
Void::Log::warn("YouTubeClient", "{}",
"URL shortening timed out after 3s, detaching thread");
shortenThread.detach();
}