Merge branch 'main' into better-layouts

This commit is contained in:
HJfod 2023-02-13 19:50:37 +02:00
commit c08c19b440
2 changed files with 28 additions and 21 deletions

View file

@ -108,25 +108,19 @@ namespace geode {
class GEODE_DLL Logger { class GEODE_DLL Logger {
private: private:
static inline std::vector<Log> s_logs; static std::vector<Log>& logs();
static inline std::ofstream s_logStream; static std::ofstream& logStream();
Logger() = delete; Logger() = delete;
~Logger() = delete; ~Logger() = delete;
// logs // logs
static void _push(Log&& log);
public: public:
static void setup(); static void setup();
static inline void push(Log&& log) { static void push(Log&& log);
Logger::_push(std::move(log));
}
static inline void pop(Log* log) { static void pop(Log* log);
geode::utils::ranges::remove(Logger::s_logs, *log);
}
static std::vector<Log*> list(); static std::vector<Log*> list();
static void clear(); static void clear();

View file

@ -183,30 +183,43 @@ void Log::addFormat(std::string_view formatStr, std::span<ComponentTrait*> compo
// Logger // Logger
void Logger::setup() { std::vector<Log>& Logger::logs() {
s_logStream = std::ofstream(dirs::getGeodeLogDir() / log::generateLogName()); static std::vector<Log> 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); std::string logStr = log.toString(true);
LoaderImpl::get()->logConsoleMessage(logStr); LoaderImpl::get()->logConsoleMessage(logStr);
s_logStream << logStr << std::endl; logStream() << logStr << std::endl;
s_logs.emplace_back(std::forward<Log>(log)); logs().emplace_back(std::forward<Log>(log));
}
void Logger::pop(Log* log) {
geode::utils::ranges::remove(Logger::logs(), *log);
} }
std::vector<Log*> Logger::list() { std::vector<Log*> Logger::list() {
std::vector<Log*> logs; std::vector<Log*> logs_;
logs.reserve(s_logs.size()); logs_.reserve(logs().size());
for (auto& log : s_logs) { for (auto& log : logs()) {
logs.push_back(&log); logs_.push_back(&log);
} }
return logs; return logs_;
} }
void Logger::clear() { void Logger::clear() {
s_logs.clear(); logs().clear();
} }
// Misc // Misc