Optimize logging and make world packet parser callback-safe

This commit is contained in:
Kelsi 2026-02-22 06:38:41 -08:00
parent 85c8b5d5f4
commit 4ea4cb761c
5 changed files with 49 additions and 27 deletions

View file

@ -16,6 +16,11 @@ Logger& Logger::getInstance() {
void Logger::ensureFile() {
if (fileReady) return;
fileReady = true;
if (const char* logStdout = std::getenv("WOWEE_LOG_STDOUT")) {
if (logStdout[0] == '0') {
echoToStdout_ = false;
}
}
if (const char* flushMs = std::getenv("WOWEE_LOG_FLUSH_MS")) {
char* end = nullptr;
unsigned long parsed = std::strtoul(flushMs, &end, 10);
@ -67,7 +72,9 @@ void Logger::log(LogLevel level, const std::string& message) {
line << "] " << message;
std::cout << line.str() << '\n';
if (echoToStdout_) {
std::cout << line.str() << '\n';
}
if (fileStream.is_open()) {
fileStream << line.str() << '\n';
bool shouldFlush = (level >= LogLevel::WARNING);