mirror of
https://github.com/MobileGL-Dev/MobileGL
synced 2026-09-11 21:58:31 +09:00
[Chore] (MG_Util/Debug/Log): give up on stacktrace
This commit is contained in:
+2
-1
@@ -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
|
||||||
|
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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);
|
||||||
|
|||||||
Reference in New Issue
Block a user