78 lines
2.3 KiB
C++
78 lines
2.3 KiB
C++
#pragma once
|
|
|
|
#include <LoggerInterface.hpp>
|
|
#include <atomic>
|
|
#include <cstdint>
|
|
#include <filesystem>
|
|
#include <memory>
|
|
#include <mutex>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace Void::Logging
|
|
{
|
|
class MultiLogger;
|
|
} // namespace Void::Logging
|
|
|
|
namespace Echoion::Core
|
|
{
|
|
|
|
// ILogger implementation backed by the Void::Logging framework.
|
|
//
|
|
// Output is produced by a Void MultiLogger fanning out to:
|
|
// * a ConsoleLogger (stdout),
|
|
// * a SplitFileLogger writing per-level files (<dir>/<level>.log) plus a
|
|
// combined <dir>/all.log, each rolling independently by size, and
|
|
// * a CallbackLogger bridging back to the registered ILogger callbacks.
|
|
// The ILogger surface (levels, callbacks, console/file toggles, rotation
|
|
// knobs) is preserved so existing call sites and the ECHOION_LOG_* macros
|
|
// keep working unchanged.
|
|
class Logger : public Api::ILogger
|
|
{
|
|
public:
|
|
|
|
explicit Logger(std::string_view logDir = "logs",
|
|
std::string_view baseName = "echoion");
|
|
~Logger() override;
|
|
|
|
void log(Api::LogLevel level, std::string_view message,
|
|
std::source_location location) override;
|
|
void setMinLevel(Api::LogLevel level) override;
|
|
[[nodiscard]] Api::LogLevel getMinLevel() const override;
|
|
void registerCallback(const LogCallback& callback) override;
|
|
void unregisterCallback(const LogCallback& callback) override;
|
|
|
|
void flush();
|
|
void setConsoleOutput(bool enabled);
|
|
void setFileOutput(bool enabled);
|
|
void setMaxFileSize(uint64_t bytes);
|
|
void setMaxFiles(uint32_t count);
|
|
|
|
private:
|
|
|
|
// (Re)assemble the Void sink tree from the current toggles/limits.
|
|
void rebuildSinks();
|
|
// Fan a Void log entry out to the registered ILogger callbacks.
|
|
void dispatchToCallbacks(Api::LogLevel level,
|
|
const std::string& message,
|
|
const std::string& file, uint32_t line,
|
|
const std::string& function);
|
|
|
|
std::filesystem::path logDir_;
|
|
std::string baseName_;
|
|
|
|
std::shared_ptr<Void::Logging::MultiLogger> sink_;
|
|
std::mutex sinkMutex_;
|
|
|
|
std::atomic<Api::LogLevel> minLevel_{Api::LogLevel::Info};
|
|
std::atomic<bool> consoleOutput_{true};
|
|
std::atomic<bool> fileOutput_{true};
|
|
std::atomic<uint64_t> maxFileSize_{10 * 1024 * 1024}; // 10 MB
|
|
std::atomic<uint32_t> maxFiles_{5};
|
|
|
|
std::vector<LogCallback> callbacks_;
|
|
std::mutex callbackMutex_;
|
|
};
|
|
|
|
} // namespace Echoion::Core
|