diff --git a/loader/include/Geode/loader/Log.hpp b/loader/include/Geode/loader/Log.hpp index bea6cd1b..8681efaf 100644 --- a/loader/include/Geode/loader/Log.hpp +++ b/loader/include/Geode/loader/Log.hpp @@ -108,25 +108,19 @@ namespace geode { class GEODE_DLL Logger { private: - static inline std::vector s_logs; - static inline std::ofstream s_logStream; + static std::vector& logs(); + static std::ofstream& logStream(); Logger() = delete; ~Logger() = delete; // logs - static void _push(Log&& log); - public: static void setup(); - static inline void push(Log&& log) { - Logger::_push(std::move(log)); - } + static void push(Log&& log); - static inline void pop(Log* log) { - geode::utils::ranges::remove(Logger::s_logs, *log); - } + static void pop(Log* log); static std::vector list(); static void clear(); diff --git a/loader/src/loader/Log.cpp b/loader/src/loader/Log.cpp index c9204b71..61f4f3cb 100644 --- a/loader/src/loader/Log.cpp +++ b/loader/src/loader/Log.cpp @@ -183,30 +183,43 @@ void Log::addFormat(std::string_view formatStr, std::span compo // Logger -void Logger::setup() { - s_logStream = std::ofstream(dirs::getGeodeLogDir() / log::generateLogName()); +std::vector& Logger::logs() { + static std::vector logs; + return logs; +} +std::ofstream& Logger::logStream() { + static std::ofstream logStream; + return logStream; } -void Logger::_push(Log&& log) { +void Logger::setup() { + logStream() = std::ofstream(dirs::getGeodeLogDir() / log::generateLogName()); +} + +void Logger::push(Log&& log) { std::string logStr = log.toString(true); LoaderImpl::get()->logConsoleMessage(logStr); - s_logStream << logStr << std::endl; + logStream() << logStr << std::endl; - s_logs.emplace_back(std::forward(log)); + logs().emplace_back(std::forward(log)); +} + +void Logger::pop(Log* log) { + geode::utils::ranges::remove(Logger::logs(), *log); } std::vector Logger::list() { - std::vector logs; - logs.reserve(s_logs.size()); - for (auto& log : s_logs) { - logs.push_back(&log); + std::vector logs_; + logs_.reserve(logs().size()); + for (auto& log : logs()) { + logs_.push_back(&log); } - return logs; + return logs_; } void Logger::clear() { - s_logs.clear(); + logs().clear(); } // Misc