Fix file logging on Android

This commit is contained in:
Luke Street
2026-05-12 14:00:04 -06:00
parent f39195c5e0
commit 2b9ed729a3
+19 -8
View File
@@ -109,6 +109,16 @@ void WriteLogLine(FILE* out, const char* levelStr, const char* module, const cha
std::fputc('\n', out);
std::fflush(out);
}
void WriteLogLineToFile(
const char* levelStr, const char* module, const char* message, unsigned int len) {
if (g_logStateAlive.load(std::memory_order_acquire)) {
std::lock_guard lock(g_logState.mutex);
if (g_logState.file != nullptr) {
WriteLogLine(g_logState.file, levelStr, module, message, len);
}
}
}
} // namespace
static bool IsForStubLog(const char* message) {
@@ -132,6 +142,11 @@ void aurora_log_callback(AuroraLogLevel level, const char* module, const char* m
return;
}
if (module == nullptr) {
module = "";
}
const char* levelStr = LogLevelString(level);
int android_log_level = 0;
switch (level) {
case LOG_DEBUG:
@@ -151,12 +166,14 @@ void aurora_log_callback(AuroraLogLevel level, const char* module, const char* m
break;
}
std::stringstream msgStream(message);
std::stringstream msgStream(std::string(message, len));
std::string segment;
while(std::getline(msgStream, segment)) {
__android_log_print(android_log_level, module, "%s\n", segment.c_str());
}
WriteLogLineToFile(levelStr, module, message, len);
if (level == LOG_FATAL) {
abort();
}
@@ -177,13 +194,7 @@ void aurora_log_callback(AuroraLogLevel level, const char* module, const char* m
const char* levelStr = LogLevelString(level);
FILE* out = LogStreamForLevel(level);
WriteLogLine(out, levelStr, module, message, len);
if (g_logStateAlive.load(std::memory_order_acquire)) {
std::lock_guard lock(g_logState.mutex);
if (g_logState.file != nullptr) {
WriteLogLine(g_logState.file, levelStr, module, message, len);
}
}
WriteLogLineToFile(levelStr, module, message, len);
if (level == LOG_FATAL) {
abort();