Delete the ILogger/LoggerRegistry layer (logging is Void::Log now)
Remove logger/LoggerInterface.hpp entirely — ILogger, LoggerRegistry, Api::LogLevel, Api::LogEntry, and the ECHOION_LOG_* macros — and drop it from the api.hpp aggregate. All logging goes through the Void::Log facade. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
95454f9d83
commit
e2e4214687
2 files changed
-167
No files matched your search
@@ -9,7 +9,6 @@
|
||||
// Granular type modules
|
||||
#include "api/audio/AudioTypes.hpp"
|
||||
#include "api/config/ConfigTypes.hpp"
|
||||
#include "api/logger/LoggerInterface.hpp"
|
||||
#include "api/network/NetworkInterface.hpp"
|
||||
#include "api/network/NetworkTypes.hpp"
|
||||
#include "api/plugin/PluginTypes.hpp"
|
||||
|
||||
@@ -1,166 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include "Types.hpp"
|
||||
#include <format>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <source_location>
|
||||
#include <string>
|
||||
|
||||
namespace Echoion::Api
|
||||
{
|
||||
|
||||
// Logger interface for the user's custom logger implementation
|
||||
class ILogger
|
||||
{
|
||||
public:
|
||||
|
||||
virtual ~ILogger() = default;
|
||||
|
||||
// Core logging method
|
||||
virtual void log(LogLevel level, std::string_view message,
|
||||
std::source_location location =
|
||||
std::source_location::current()) = 0;
|
||||
|
||||
// Convenience methods
|
||||
virtual void debug(
|
||||
std::string_view message,
|
||||
std::source_location location = std::source_location::current())
|
||||
{
|
||||
log(LogLevel::Debug, message, location);
|
||||
}
|
||||
|
||||
virtual void info(
|
||||
std::string_view message,
|
||||
std::source_location location = std::source_location::current())
|
||||
{
|
||||
log(LogLevel::Info, message, location);
|
||||
}
|
||||
|
||||
virtual void warning(
|
||||
std::string_view message,
|
||||
std::source_location location = std::source_location::current())
|
||||
{
|
||||
log(LogLevel::Warning, message, location);
|
||||
}
|
||||
|
||||
virtual void error(
|
||||
std::string_view message,
|
||||
std::source_location location = std::source_location::current())
|
||||
{
|
||||
log(LogLevel::Error, message, location);
|
||||
}
|
||||
|
||||
virtual void critical(
|
||||
std::string_view message,
|
||||
std::source_location location = std::source_location::current())
|
||||
{
|
||||
log(LogLevel::Critical, message, location);
|
||||
}
|
||||
|
||||
// Template method for formatted logging
|
||||
template <typename... Args>
|
||||
void logf(
|
||||
LogLevel level, std::format_string<Args...> fmt, Args&&... args,
|
||||
std::source_location location = std::source_location::current())
|
||||
{
|
||||
log(level, std::format(fmt, std::forward<Args>(args)...),
|
||||
location);
|
||||
}
|
||||
|
||||
// Set minimum log level
|
||||
virtual void setMinLevel(LogLevel level) = 0;
|
||||
[[nodiscard]] virtual LogLevel getMinLevel() const = 0;
|
||||
|
||||
// Register log callback
|
||||
using LogCallback = std::function<void(const LogEntry&)>;
|
||||
virtual void registerCallback(const LogCallback& callback) = 0;
|
||||
virtual void unregisterCallback(const LogCallback& callback) = 0;
|
||||
};
|
||||
|
||||
using LoggerPtr = std::shared_ptr<ILogger>;
|
||||
|
||||
// Global logger accessor
|
||||
class LoggerRegistry
|
||||
{
|
||||
public:
|
||||
|
||||
static LoggerRegistry& instance()
|
||||
{
|
||||
static LoggerRegistry instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
void setLogger(LoggerPtr logger) { logger_ = std::move(logger); }
|
||||
[[nodiscard]] LoggerPtr getLogger() const { return logger_; }
|
||||
|
||||
[[nodiscard]] bool hasLogger() const noexcept
|
||||
{
|
||||
return static_cast<bool>(logger_);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
LoggerRegistry() = default;
|
||||
LoggerPtr logger_;
|
||||
};
|
||||
|
||||
// Convenience macros
|
||||
#define ECHOION_LOG_DEBUG(msg) \
|
||||
do { \
|
||||
if (auto logger = \
|
||||
Echoion::Api::LoggerRegistry::instance().getLogger(); \
|
||||
logger) { \
|
||||
logger->debug(msg); \
|
||||
} else { \
|
||||
std::cout << "[DEBUG] Echoion: " << std::string(msg) << std::endl; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ECHOION_LOG_INFO(msg) \
|
||||
do { \
|
||||
if (auto logger = \
|
||||
Echoion::Api::LoggerRegistry::instance().getLogger(); \
|
||||
logger) { \
|
||||
logger->info(msg); \
|
||||
} else { \
|
||||
std::cout << "[INFO] Echoion: " << std::string(msg) << std::endl; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ECHOION_LOG_WARNING(msg) \
|
||||
do { \
|
||||
if (auto logger = \
|
||||
Echoion::Api::LoggerRegistry::instance().getLogger(); \
|
||||
logger) { \
|
||||
logger->warning(msg); \
|
||||
} else { \
|
||||
std::cout << "[WARNING] Echoion: " << std::string(msg) \
|
||||
<< std::endl; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ECHOION_LOG_ERROR(msg) \
|
||||
do { \
|
||||
if (auto logger = \
|
||||
Echoion::Api::LoggerRegistry::instance().getLogger(); \
|
||||
logger) { \
|
||||
logger->error(msg); \
|
||||
} else { \
|
||||
std::cerr << "[ERROR] Echoion: " << std::string(msg) << std::endl; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define ECHOION_LOG_CRITICAL(msg) \
|
||||
do { \
|
||||
if (auto logger = \
|
||||
Echoion::Api::LoggerRegistry::instance().getLogger(); \
|
||||
logger) { \
|
||||
logger->critical(msg); \
|
||||
} else { \
|
||||
std::cerr << "[CRITICAL] Echoion: " << std::string(msg) \
|
||||
<< std::endl; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
} // namespace Echoion::Api
|
||||
Reference in new issue
Block a user