Files
ReshadePluginsCore/libs/Logger/Logger.hpp
2026-02-01 20:40:18 +01:00

29 lines
982 B
C++

#pragma once
#include <memory>
#include <filesystem>
#include <spdlog/spdlog.h>
#include <spdlog/sinks/rotating_file_sink.h>
#include <Windows.h>
inline std::shared_ptr<spdlog::logger> InitializeLogger(const char* logger_name, const std::string& pluginLog) {
try {
std::filesystem::path log_path = std::filesystem::absolute(pluginLog);
if (std::filesystem::exists(log_path))
std::filesystem::remove(log_path);
auto logger = std::make_shared<spdlog::logger>(logger_name,std::make_shared<spdlog::sinks::rotating_file_sink_st>(
pluginLog, 10 * 1024 * 1024,1));
logger->set_level(spdlog::level::debug);
logger->flush_on(spdlog::level::debug);
spdlog::register_logger(logger);
return logger;
}
catch (const spdlog::spdlog_ex&) {
MessageBoxA(nullptr,("Could not open " + std::string(pluginLog)).c_str(),"Logger Error",MB_ICONERROR | MB_OK);
return nullptr;
}
}