mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-23 07:57:51 -05:00
Merge branch 'main' into better-layouts
This commit is contained in:
commit
c08c19b440
2 changed files with 28 additions and 21 deletions
|
@ -108,25 +108,19 @@ namespace geode {
|
|||
|
||||
class GEODE_DLL Logger {
|
||||
private:
|
||||
static inline std::vector<Log> s_logs;
|
||||
static inline std::ofstream s_logStream;
|
||||
static std::vector<Log>& 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<Log*> list();
|
||||
static void clear();
|
||||
|
|
|
@ -183,30 +183,43 @@ void Log::addFormat(std::string_view formatStr, std::span<ComponentTrait*> compo
|
|||
|
||||
// Logger
|
||||
|
||||
void Logger::setup() {
|
||||
s_logStream = std::ofstream(dirs::getGeodeLogDir() / log::generateLogName());
|
||||
std::vector<Log>& Logger::logs() {
|
||||
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);
|
||||
|
||||
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*> logs;
|
||||
logs.reserve(s_logs.size());
|
||||
for (auto& log : s_logs) {
|
||||
logs.push_back(&log);
|
||||
std::vector<Log*> 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
|
||||
|
|
Loading…
Reference in a new issue