From c8d9d100cf6133a60cfaa29505e32e7a42baf050 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 20 Nov 2023 22:52:33 +0100 Subject: [PATCH] (Android) Added log output support --- es-core/src/Log.cpp | 14 ++++++++++++++ es-core/src/Log.h | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/es-core/src/Log.cpp b/es-core/src/Log.cpp index 4807bd7ee..f3d8e65bd 100644 --- a/es-core/src/Log.cpp +++ b/es-core/src/Log.cpp @@ -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 } diff --git a/es-core/src/Log.h b/es-core/src/Log.h index 0f165cd04..0c9c31528 100644 --- a/es-core/src/Log.h +++ b/es-core/src/Log.h @@ -19,6 +19,10 @@ #include #include +#if defined(__ANDROID__) +#include +#endif + #define LOG(level) \ if (level > Log::getReportingLevel()) \ ; \