[Chore] (MG_Util/Debug/Log): give up on stacktrace

This commit is contained in:
2026-01-05 10:03:14 +08:00
parent c6443e5039
commit 5e9844a4e5
3 changed files with 15 additions and 2 deletions
+2 -1
View File
@@ -45,7 +45,8 @@
#define MOBILEGL_LOG_ENABLE_ANDROID 1 #define MOBILEGL_LOG_ENABLE_ANDROID 1
// Require C++23 // Require C++23
#if __cplusplus >= 202302L // Android NDK still doesn't have support for that :(
#if __cplusplus >= 202302L && !__ANDROID__
#define MOBILEGL_LOG_ENABLE_STACKTRACE 1 #define MOBILEGL_LOG_ENABLE_STACKTRACE 1
#endif #endif
+3
View File
@@ -41,6 +41,9 @@
#include <unordered_map> #include <unordered_map>
#include <mutex> #include <mutex>
#include <bitset> #include <bitset>
#if __cplusplus >= 202302L && MOBILEGL_LOG_ENABLE_STACKTRACE
#include <stacktrace>
#endif
// Include FastSTL // Include FastSTL
#include <FastSTL/UnorderedMap.h> #include <FastSTL/UnorderedMap.h>
+10 -1
View File
@@ -76,6 +76,11 @@ namespace MobileGL {
void Log(const char* levelTag, android_LogPriority androidLogLevel, const char* fmt, ...) { void Log(const char* levelTag, android_LogPriority androidLogLevel, const char* fmt, ...) {
std::lock_guard<std::mutex> lock(s_mutex); std::lock_guard<std::mutex> lock(s_mutex);
#if MOBILEGL_LOG_ENABLE_STACKTRACE
auto trace = std::stacktrace::current();
std::string padding(4 * trace.size(), ' ');
#endif
std::string header = std::string header =
"[" + GetCurrentTime() + "] [" + GetOSName() + " " + GetThreadName() + "/" + levelTag + "]: "; "[" + GetCurrentTime() + "] [" + GetOSName() + " " + GetThreadName() + "/" + levelTag + "]: ";
@@ -83,7 +88,11 @@ namespace MobileGL {
va_list args; va_list args;
va_start(args, fmt); va_start(args, fmt);
int n = std::vsnprintf(buffer, sizeof(buffer), fmt, args); int n = std::vsnprintf(buffer, sizeof(buffer), fmt, args);
std::string out = header + std::string(buffer, n) + "\n"; std::string out = header +
#if MOBILEGL_LOG_ENABLE_STACKTRACE
padding +
#endif
std::string(buffer, n) + "\n";
#if MOBILEGL_LOG_ENABLE_CONSOLE #if MOBILEGL_LOG_ENABLE_CONSOLE
std::fwrite(out.c_str(), 1, out.size(), stdout); std::fwrite(out.c_str(), 1, out.size(), stdout);