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

+116 -82
View File
@@ -1,7 +1,5 @@
#include "LoggerInterface.hpp"
#include "echoion/core/ConfigLoader.hpp"
#include "echoion/core/Core.hpp"
#include "echoion/core/Logger.hpp"
#include "echoion/core/state/StateSerializer.hpp"
#include "echoion/core/state/StateVersions.hpp"
#include <ConfigManager.hpp>
@@ -9,13 +7,52 @@
#include <Events.hpp>
#include <Void/Data/Json.hpp>
#include <Void/Data/Reflect.hpp>
#include <Void/Log/ConsoleLogger.hpp>
#include <Void/Log/Formatter.hpp>
#include <Void/Log/Log.hpp>
#include <Void/Log/LoggingAdapter.hpp>
#include <Void/Log/Sinks.hpp>
#include <Void/Log/SplitFileLogger.hpp>
#include <algorithm>
#include <ctime>
#include <format>
#include <iomanip>
#include <iostream>
#include <sstream>
#include <thread>
namespace Echoion::Core
{
namespace
{
// Build the console + split-file logging stack and install it as the
// process-wide Void::Log sink. Replaces the old ILogger/LoggerRegistry
// indirection; every ECHOION_LOG_* macro is now a Void::Log:: call.
[[nodiscard]] std::shared_ptr<Void::Logging::MultiLogger>
buildLogSink()
{
namespace VL = Void::Logging;
auto multi = std::make_shared<VL::MultiLogger>();
auto formatter = std::make_shared<const VL::PatternFormatter>(
"[{time}] [{level}] [{thread}] {file} - {message}");
auto console = std::make_shared<VL::ConsoleLogger>(std::cout);
console->set_formatter(formatter);
multi->add(std::move(console));
VL::SplitFileOptions opts;
opts.combined = true;
opts.max_bytes = 10 * 1024 * 1024;
opts.max_files = 5;
if (auto fileSink = VL::SplitFileLogger::open("logs", opts)) {
(*fileSink)->set_formatter(formatter);
multi->add(std::shared_ptr<VL::Logger>(std::move(*fileSink)));
}
return multi;
}
} // namespace
} // namespace Echoion::Core
namespace Echoion::Core
{
@@ -31,6 +68,13 @@ namespace Echoion::Core
Core::Core() = default;
void Core::installLogging()
{
logSink_ = buildLogSink();
Void::Log::set_sink(Void::Log::make_sink(*logSink_));
Void::Log::set_min_level(Void::Log::Level::Debug);
}
Core::~Core()
{
if (initialized_) {
@@ -44,9 +88,7 @@ namespace Echoion::Core
return Api::fail(Api::ErrorCode::AlreadyExists,
"Core already initialized");
}
auto logger = std::make_shared<Logger>();
logger->setMinLevel(Api::LogLevel::Debug);
Api::LoggerRegistry::instance().setLogger(logger);
installLogging();
// Store config path for later reload
configPath_ = configPath;
@@ -55,7 +97,7 @@ namespace Echoion::Core
auto configResult = ConfigLoader::loadFromFile(configPath);
if (!configResult) {
// Try to create default config
ECHOION_LOG_WARNING(
Void::Log::warn("Core", "{}",
std::format("Failed to load config: {}, creating default",
configResult.error().message));
config_ = ConfigLoader::createDefaultConfig();
@@ -66,22 +108,19 @@ namespace Echoion::Core
// Initialize global ConfigManager with loaded config
configManager_.updateConfig(config_, false);
ECHOION_LOG_INFO("Global ConfigManager initialized");
Void::Log::info("Core", "{}", "Global ConfigManager initialized");
// Note: logLevel was removed from BotConfig, using Debug as default
Api::LoggerRegistry::instance().getLogger()->setMinLevel(
Api::LogLevel::Debug);
ECHOION_LOG_INFO(
Void::Log::info("Core", "{}",
std::format("Core loaded config - Server: {}:{}, Nickname: {}",
config_.teamspeak.address, config_.teamspeak.port,
config_.teamspeak.nickname));
// Initialize logger
ECHOION_LOG_INFO("Initializing Echoion Core...");
Void::Log::info("Core", "{}", "Initializing Echoion Core...");
// The async event bus runs from construction; nothing to start.
ECHOION_LOG_INFO("EventBus ready");
Void::Log::info("Core", "{}", "EventBus ready");
// Initialize network client
networkClient_ = std::make_shared<NetworkClient>();
@@ -96,12 +135,12 @@ namespace Echoion::Core
dbConfig.path = configPath.parent_path() / "echoion.db";
auto dbResult = database_->initialize(dbConfig);
if (!dbResult) {
ECHOION_LOG_WARNING(std::format("Failed to initialize database: {}",
Void::Log::warn("Core", "{}", std::format("Failed to initialize database: {}",
dbResult.error().message));
// Not fatal - continue without database
database_ = nullptr;
} else {
ECHOION_LOG_INFO("Database initialized successfully");
Void::Log::info("Core", "{}", "Database initialized successfully");
// Generate RPC tokens for existing subscribers
this->generateRpcTokensForSubscribers();
@@ -150,7 +189,7 @@ namespace Echoion::Core
// Check if server groups are available
if (clientInfo.serverGroups.empty()) {
ECHOION_LOG_WARNING(
Void::Log::warn("Core", "{}",
"Cannot check admin permissions: server "
"groups not available for client " +
std::to_string(clientId));
@@ -190,7 +229,7 @@ namespace Echoion::Core
if (std::chrono::duration_cast<std::chrono::seconds>(
now - lastLog)
.count() >= 5) {
ECHOION_LOG_DEBUG(std::format(
Void::Log::debug("Core", "{}", std::format(
"Audio callback: {} calls, {} samples, result: {}",
callCount, data.size(),
result.has_value() ? "ok" : "error"));
@@ -213,25 +252,25 @@ namespace Echoion::Core
[this](uint64_t clientId)
-> std::optional<std::pair<std::string, std::string>> {
if (!pluginInterface_) {
ECHOION_LOG_WARNING(
Void::Log::warn("Core", "{}",
"ClientInfoCallback: pluginInterface is null");
return std::nullopt;
}
auto clientInfoResult = pluginInterface_->getClient(clientId);
if (!clientInfoResult || !clientInfoResult->has_value()) {
ECHOION_LOG_WARNING(std::format(
Void::Log::warn("Core", "{}", std::format(
"ClientInfoCallback: getClient failed for client {}",
clientId));
return std::nullopt;
}
auto clientInfo = clientInfoResult->value();
if (!clientInfo.uniqueIdentifier) {
ECHOION_LOG_WARNING(std::format(
Void::Log::warn("Core", "{}", std::format(
"ClientInfoCallback: client {} has no uniqueIdentifier",
clientId));
return std::nullopt;
}
ECHOION_LOG_DEBUG(
Void::Log::debug("Core", "{}",
std::format("ClientInfoCallback: Got UID for client {}: {}",
clientId, *clientInfo.uniqueIdentifier));
return std::make_pair(*clientInfo.uniqueIdentifier,
@@ -280,12 +319,12 @@ namespace Echoion::Core
config_.network.rpcPort > 0 ? config_.network.rpcPort : 8765;
auto rpcResult = rpcServer_->start(rpcPort);
if (!rpcResult) {
ECHOION_LOG_WARNING(std::format("Failed to start RPC server: {}",
Void::Log::warn("Core", "{}", std::format("Failed to start RPC server: {}",
rpcResult.error().message));
// Not fatal - continue without RPC
rpcServer_.reset();
} else {
ECHOION_LOG_INFO(
Void::Log::info("Core", "{}",
std::format("RPC server started on port {}", rpcPort));
setupRpcHandlers();
setupEventBusSubscriptions();
@@ -294,18 +333,13 @@ namespace Echoion::Core
// ── Compose the service registry ─────────────────────────────────
// Register every Core service by interface so code can resolve them
// via registry_.require<I>() instead of reaching for global singletons.
// The three former singletons (logger, config, event bus) are wrapped
// in non-owning aliasing shared_ptrs — they remain valid statics behind
// the ECHOION_LOG_*/PUBLISH/SUBSCRIBE macros, the registry just makes
// them discoverable as services too.
// Config and event bus are wrapped in non-owning aliasing shared_ptrs
// so the registry can hand them out without owning them.
{
const auto alias = [](auto* p) {
using T = std::remove_reference_t<decltype(*p)>;
return std::shared_ptr<T>(p, [](T*) {});
};
if (auto logger = Api::LoggerRegistry::instance().getLogger()) {
registry_.provide<Api::ILogger>(logger);
}
registry_.provide<Api::ConfigManager>(
alias(&configManager_));
registry_.provide<Void::EventBus::EventBus>(alias(&eventBus_));
@@ -321,22 +355,22 @@ namespace Echoion::Core
if (rpcServer_) {
registry_.provide<RpcServer>(rpcServer_);
}
ECHOION_LOG_INFO("Service registry composed");
Void::Log::info("Core", "{}", "Service registry composed");
}
startTime_ = std::chrono::system_clock::now();
initialized_ = true;
ECHOION_LOG_INFO(std::format("Core initialized (this={})",
Void::Log::info("Core", "{}", std::format("Core initialized (this={})",
reinterpret_cast<uintptr_t>(this)));
unsigned int hwThreads = std::thread::hardware_concurrency();
ECHOION_LOG_INFO(
Void::Log::info("Core", "{}",
std::format("Hardware concurrency: {} threads", hwThreads));
ECHOION_LOG_INFO("Echoion Core initialized successfully");
Void::Log::info("Core", "{}", "Echoion Core initialized successfully");
// Auto-connect to server if configured
if (!config_.teamspeak.address.empty() && pluginInterface_) {
ECHOION_LOG_INFO(std::format("Auto-connecting to {}:{}...",
Void::Log::info("Core", "{}", std::format("Auto-connecting to {}:{}...",
config_.teamspeak.address,
config_.teamspeak.port));
@@ -355,10 +389,10 @@ namespace Echoion::Core
auto connectResult =
pluginInterface_->connectToServer(serverConfig);
if (!connectResult) {
ECHOION_LOG_ERROR(std::format("Auto-connect failed: {}",
Void::Log::error("Core", "{}", std::format("Auto-connect failed: {}",
connectResult.error().message));
} else {
ECHOION_LOG_INFO("Auto-connect initiated");
Void::Log::info("Core", "{}", "Auto-connect initiated");
}
}
@@ -371,7 +405,7 @@ namespace Echoion::Core
return {};
}
ECHOION_LOG_INFO("Shutting down Echoion Core...");
Void::Log::info("Core", "{}", "Shutting down Echoion Core...");
if (commandManager_) {
commandManager_->shutdown();
@@ -397,7 +431,7 @@ namespace Echoion::Core
// Drain any in-flight event dispatch.
eventBus_.flush();
ECHOION_LOG_INFO("EventBus stopped");
Void::Log::info("Core", "{}", "EventBus stopped");
// Clear callbacks
{
@@ -406,7 +440,7 @@ namespace Echoion::Core
}
initialized_ = false;
ECHOION_LOG_INFO(std::format("Echoion Core shutdown complete (this={})",
Void::Log::info("Core", "{}", std::format("Echoion Core shutdown complete (this={})",
reinterpret_cast<uintptr_t>(this)));
return {};
}
@@ -902,7 +936,7 @@ namespace Echoion::Core
commandManager_->setServerConfig(config_);
}
ECHOION_LOG_INFO("Configuration reloaded from disk");
Void::Log::info("Core", "{}", "Configuration reloaded from disk");
return {};
}
@@ -913,7 +947,7 @@ namespace Echoion::Core
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
}
ECHOION_LOG_INFO("Preparing for hot reload...");
Void::Log::info("Core", "{}", "Preparing for hot reload...");
broadcastEvent(
Api::PluginEvent{.type = Api::PluginEventType::HotReloadRequested,
@@ -931,7 +965,7 @@ namespace Echoion::Core
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
}
ECHOION_LOG_INFO("Restoring after hot reload...");
Void::Log::info("Core", "{}", "Restoring after hot reload...");
auto result = musicManager_->restoreFromHotReload(state);
if (!result) {
@@ -943,7 +977,7 @@ namespace Echoion::Core
.clientId = 0,
.timestamp = std::chrono::system_clock::now()});
ECHOION_LOG_INFO("Hot reload restore complete");
Void::Log::info("Core", "{}", "Hot reload restore complete");
return {};
}
@@ -954,7 +988,7 @@ namespace Echoion::Core
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
}
ECHOION_LOG_INFO("Preparing for hot reload (decoupled)...");
Void::Log::info("Core", "{}", "Preparing for hot reload (decoupled)...");
broadcastEvent(
Api::PluginEvent{.type = Api::PluginEventType::HotReloadRequested,
@@ -974,7 +1008,7 @@ namespace Echoion::Core
Api::ErrorCode::ServiceUnavailable, "Core not initialized");
}
ECHOION_LOG_INFO("Restoring after hot reload (decoupled)...");
Void::Log::info("Core", "{}", "Restoring after hot reload (decoupled)...");
// Deserialize state from JSON
auto parsed = Void::Json::parse(state);
@@ -1005,7 +1039,7 @@ namespace Echoion::Core
.clientId = 0,
.timestamp = std::chrono::system_clock::now()});
ECHOION_LOG_INFO("Hot reload restore complete (decoupled)");
Void::Log::info("Core", "{}", "Hot reload restore complete (decoupled)");
return {};
}
@@ -1015,7 +1049,7 @@ namespace Echoion::Core
Api::StateBlob Core::saveState()
{
ECHOION_LOG_INFO("Saving Core state...");
Void::Log::info("Core", "{}", "Saving Core state...");
StateV1 state;
@@ -1055,7 +1089,7 @@ namespace Echoion::Core
// Serialize using StateSerializer
auto blob = StateSerializer::serialize(state);
ECHOION_LOG_INFO(std::format("State saved: version={}, size={} bytes",
Void::Log::info("Core", "{}", std::format("State saved: version={}, size={} bytes",
blob.version, blob.size()));
return blob;
@@ -1063,14 +1097,14 @@ namespace Echoion::Core
Api::Result<void> Core::restoreState(const Api::StateBlob& state)
{
ECHOION_LOG_INFO(
Void::Log::info("Core", "{}",
std::format("Restoring Core state: version={}", state.version));
auto result = StateSerializer::deserialize(state);
if (!result) {
// Check if it's a version issue and provide helpful message
if (result.error().code == Api::ErrorCode::IncompatibleVersion) {
ECHOION_LOG_WARNING(result.error().message);
Void::Log::warn("Core", "{}", result.error().message);
}
return std::unexpected(result.error());
}
@@ -1083,7 +1117,7 @@ namespace Echoion::Core
// Restore track, position, volume, etc.
// This would involve calling MusicManager methods
// For now, we'll just log it
ECHOION_LOG_INFO(std::format("Restoring playback: {} - {}",
Void::Log::info("Core", "{}", std::format("Restoring playback: {} - {}",
playback.currentTrack.title,
playback.currentTrack.artist));
}
@@ -1093,17 +1127,17 @@ namespace Echoion::Core
// Add to music manager queue
auto result = musicManager_->queueTrack(entry.track, 0);
if (result) {
ECHOION_LOG_INFO(
Void::Log::info("Core", "{}",
std::format("Restored queue entry: {} (ID: {})",
entry.track.title, *result));
} else {
ECHOION_LOG_WARNING(
Void::Log::warn("Core", "{}",
std::format("Failed to restore queue entry '{}': {}",
entry.track.title, result.error().message));
}
}
ECHOION_LOG_INFO("State restored successfully");
Void::Log::info("Core", "{}", "State restored successfully");
return {};
}
@@ -1200,11 +1234,11 @@ namespace Echoion::Core
Api::Result<void> Core::onPluginEvent(const Api::PluginEvent& event)
{
ECHOION_LOG_DEBUG(std::format(
Void::Log::debug("Core", "{}", std::format(
"Core::onPluginEvent called (this={}, initialized={})",
reinterpret_cast<uintptr_t>(this), initialized_.load()));
if (!initialized_) {
ECHOION_LOG_WARNING(
Void::Log::warn("Core", "{}",
std::format("Core::onPluginEvent: Core not initialized "
"(this={}), ignoring event type={}",
reinterpret_cast<uintptr_t>(this),
@@ -1216,7 +1250,7 @@ namespace Echoion::Core
// Debug logging for command events
if (event.type == Api::PluginEventType::TextMessageReceived &&
event.message) {
ECHOION_LOG_DEBUG(
Void::Log::debug("Core", "{}",
std::format("Core received message: {} from client {}",
*event.message, event.clientId));
}
@@ -1226,7 +1260,7 @@ namespace Echoion::Core
if (event.message) {
// Check if it's a command
if (event.message->starts_with(config_.bot.commandPrefix)) {
ECHOION_LOG_DEBUG(
Void::Log::debug("Core", "{}",
std::format("Processing command: {} from client {}",
*event.message, event.clientId));
// Create reply callback
@@ -1262,7 +1296,7 @@ namespace Echoion::Core
break;
case Api::PluginEventType::ClientConnected:
ECHOION_LOG_INFO(
Void::Log::info("Core", "{}",
std::format("Client {} connected, updating whisper list",
event.clientId));
if (musicManager_) {
@@ -1273,7 +1307,7 @@ namespace Echoion::Core
break;
case Api::PluginEventType::ClientDisconnected:
ECHOION_LOG_INFO(
Void::Log::info("Core", "{}",
std::format("Client {} disconnected", event.clientId));
if (musicManager_) {
musicManager_->onClientDisconnected(event.clientId);
@@ -1301,7 +1335,7 @@ namespace Echoion::Core
void Core::setPluginInterface(Api::PluginInterfacePtr pluginInterface)
{
pluginInterface_ = std::move(pluginInterface);
ECHOION_LOG_INFO(std::format("Plugin interface set (this={})",
Void::Log::info("Core", "{}", std::format("Plugin interface set (this={})",
reinterpret_cast<uintptr_t>(this)));
// Now that we have the plugin interface, update the whisper list
@@ -1311,7 +1345,7 @@ namespace Echoion::Core
// Trigger auto-connect now that plugin interface is available
if (initialized_ && !config_.teamspeak.address.empty()) {
ECHOION_LOG_INFO(
Void::Log::info("Core", "{}",
"Plugin interface available, triggering auto-connect...");
triggerAutoConnect();
}
@@ -1320,23 +1354,23 @@ namespace Echoion::Core
void Core::triggerAutoConnect()
{
if (!initialized_) {
ECHOION_LOG_WARNING("Cannot auto-connect: Core not initialized");
Void::Log::warn("Core", "{}", "Cannot auto-connect: Core not initialized");
return;
}
if (!pluginInterface_) {
ECHOION_LOG_WARNING(
Void::Log::warn("Core", "{}",
"Cannot auto-connect: Plugin interface not set");
return;
}
if (config_.teamspeak.address.empty()) {
ECHOION_LOG_INFO(
Void::Log::info("Core", "{}",
"Auto-connect skipped: No server address configured");
return;
}
ECHOION_LOG_INFO(std::format("Auto-connecting to {}:{}...",
Void::Log::info("Core", "{}", std::format("Auto-connecting to {}:{}...",
config_.teamspeak.address,
config_.teamspeak.port));
@@ -1354,10 +1388,10 @@ namespace Echoion::Core
auto connectResult = pluginInterface_->connectToServer(serverConfig);
if (!connectResult) {
ECHOION_LOG_ERROR(std::format("Auto-connect failed: {}",
Void::Log::error("Core", "{}", std::format("Auto-connect failed: {}",
connectResult.error().message));
} else {
ECHOION_LOG_INFO("Auto-connect initiated");
Void::Log::info("Core", "{}", "Auto-connect initiated");
}
}
@@ -1378,7 +1412,7 @@ namespace Echoion::Core
try {
callback(event);
} catch (const std::exception& e) {
ECHOION_LOG_ERROR(
Void::Log::error("Core", "{}",
std::format("Event callback error: {}", e.what()));
}
}
@@ -1470,7 +1504,7 @@ namespace Echoion::Core
void Core::updateWhisperList()
{
if (!pluginInterface_ || !musicManager_) {
ECHOION_LOG_WARNING(
Void::Log::warn("Core", "{}",
"updateWhisperList: pluginInterface or musicManager is null");
return;
}
@@ -1479,16 +1513,16 @@ namespace Echoion::Core
std::vector<uint64_t> subscriberVec(subscribers.begin(),
subscribers.end());
ECHOION_LOG_INFO(
Void::Log::info("Core", "{}",
std::format("Updating whisper list with {} online subscribers",
subscriberVec.size()));
auto result = pluginInterface_->setWhisperList(subscriberVec);
if (!result) {
ECHOION_LOG_WARNING(std::format("Failed to update whisper list: {}",
Void::Log::warn("Core", "{}", std::format("Failed to update whisper list: {}",
result.error().message));
} else {
ECHOION_LOG_INFO("Whisper list updated successfully");
Void::Log::info("Core", "{}", "Whisper list updated successfully");
}
}
@@ -1621,7 +1655,7 @@ namespace Echoion::Core
tsClientId, pmMessage);
if (!pmResult) {
ECHOION_LOG_WARNING(std::format(
Void::Log::warn("Core", "{}", std::format(
"Failed to send PM with token: {}",
pmResult.error().message));
}
@@ -1793,7 +1827,7 @@ namespace Echoion::Core
return json;
});
ECHOION_LOG_INFO("RPC handlers registered");
Void::Log::info("Core", "{}", "RPC handlers registered");
}
void Core::setupEventBusSubscriptions() noexcept
@@ -2014,7 +2048,7 @@ namespace Echoion::Core
}
});
ECHOION_LOG_INFO("EventBus subscriptions set up");
Void::Log::info("Core", "{}", "EventBus subscriptions set up");
}
void Core::generateRpcTokensForSubscribers()
@@ -2023,12 +2057,12 @@ namespace Echoion::Core
return;
}
ECHOION_LOG_INFO("Generating RPC tokens for existing subscribers...");
Void::Log::info("Core", "{}", "Generating RPC tokens for existing subscribers...");
// Get all subscriber UIDs
auto uidsResult = database_->getAllSubscriberUids();
if (!uidsResult) {
ECHOION_LOG_WARNING(std::format("Failed to get subscriber UIDs: {}",
Void::Log::warn("Core", "{}", std::format("Failed to get subscriber UIDs: {}",
uidsResult.error().message));
return;
}
@@ -2040,7 +2074,7 @@ namespace Echoion::Core
// Check if token already exists
auto existingToken = database_->getExistingRpcToken(uid);
if (!existingToken) {
ECHOION_LOG_WARNING(
Void::Log::warn("Core", "{}",
std::format("Failed to check existing token for UID {}: {}",
uid, existingToken.error().message));
continue;
@@ -2054,7 +2088,7 @@ namespace Echoion::Core
// Generate new token
auto tokenResult = database_->generateRpcToken(uid);
if (!tokenResult) {
ECHOION_LOG_WARNING(
Void::Log::warn("Core", "{}",
std::format("Failed to generate token for UID {}: {}", uid,
tokenResult.error().message));
} else {
@@ -2062,7 +2096,7 @@ namespace Echoion::Core
}
}
ECHOION_LOG_INFO(std::format("RPC token generation complete: {} new "
Void::Log::info("Core", "{}", std::format("RPC token generation complete: {} new "
"tokens generated, {} already existed",
generatedCount, existingCount));
}