(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();
#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 (mMessageLevel == LogError || sReportingLevel >= LogDebug)
std::cerr << mOutStringStream.str();
#endif
}

View file

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