(Android) Added log output support

This commit is contained in:
Leon Styhre 2023-11-20 22:52:33 +01:00
parent 27be4007a2
commit c8d9d100cf
2 changed files with 18 additions and 0 deletions

View file

@ -91,7 +91,21 @@ Log::~Log()
sFile << mOutStringStream.str(); sFile << mOutStringStream.str();
#if defined(__ANDROID__)
if (mMessageLevel == LogError) {
__android_log_print(ANDROID_LOG_ERROR, nullptr, "%s", mOutStringStream.str().c_str());
}
else if (sReportingLevel >= LogDebug) {
if (mMessageLevel == LogInfo)
__android_log_print(ANDROID_LOG_INFO, nullptr, "%s", mOutStringStream.str().c_str());
else if (mMessageLevel == LogWarning)
__android_log_print(ANDROID_LOG_WARN, nullptr, "%s", mOutStringStream.str().c_str());
else
__android_log_print(ANDROID_LOG_DEBUG, nullptr, "%s", mOutStringStream.str().c_str());
}
#else
// If it's an error or the --debug flag has been set, then print to the console as well. // If it's an error or the --debug flag has been set, then print to the console as well.
if (mMessageLevel == LogError || sReportingLevel >= LogDebug) if (mMessageLevel == LogError || sReportingLevel >= LogDebug)
std::cerr << mOutStringStream.str(); std::cerr << mOutStringStream.str();
#endif
} }

View file

@ -19,6 +19,10 @@
#include <mutex> #include <mutex>
#include <sstream> #include <sstream>
#if defined(__ANDROID__)
#include <android/log.h>
#endif
#define LOG(level) \ #define LOG(level) \
if (level > Log::getReportingLevel()) \ if (level > Log::getReportingLevel()) \
; \ ; \