From 84534cf5d7a3733644af156088ad7e080d8c8265 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 27 Nov 2023 20:19:35 +0100 Subject: [PATCH] (Android) Added the application ID to the log output Also changed the general log output formatting slightly --- CMakeLists.txt | 1 + es-app/src/main.cpp | 17 ++++++----------- es-core/src/Log.cpp | 23 +++++++++++++++-------- es-core/src/Log.h | 2 +- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 81e05743d..55aab8d58 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -286,6 +286,7 @@ endif() if(ANDROID) set(BUNDLED_CERTS ON) + add_compile_definitions(ANDROID_APPLICATION_ID="org.es_de.frontend") endif() if(WIN32) diff --git a/es-app/src/main.cpp b/es-app/src/main.cpp index 477c14dbd..8f13f39c9 100644 --- a/es-app/src/main.cpp +++ b/es-app/src/main.cpp @@ -1,20 +1,15 @@ // SPDX-License-Identifier: MIT // -// EmulationStation Desktop Edition (ES-DE) is a frontend for browsing -// and launching games from your multi-platform game collection. -// -// Originally created by Alec Lofquist. -// Improved and extended by the RetroPie community. -// Desktop Edition fork by Leon Styhre. +// ES-DE is a frontend for browsing and launching games from your multi-platform game collection. // // The column limit is 100 characters. // All ES-DE C++ source code is formatted using clang-format. // // main.cpp // -// Main program loop. Interprets command-line arguments, checks for the -// home folder and es_settings.xml configuration file, sets up the application -// environment and starts listening to SDL events. +// Main program loop. Interprets command-line arguments, checks for the home folder +// and es_settings.xml configuration file, sets up the application environment and +// starts listening to SDL events. // #include "ApplicationUpdater.h" @@ -452,7 +447,7 @@ bool checkApplicationHomeDirectory() std::cout << "First startup, creating application home directory \"" << Utils::String::replace(applicationHome, "/", "\\") << "\"\n"; #elif defined(__ANDROID__) - __android_log_print(ANDROID_LOG_VERBOSE, nullptr, + __android_log_print(ANDROID_LOG_VERBOSE, ANDROID_APPLICATION_ID, "First startup, creating application home directory \"%s\"", applicationHome.c_str()); #else @@ -462,7 +457,7 @@ bool checkApplicationHomeDirectory() Utils::FileSystem::createDirectory(applicationHome); if (!Utils::FileSystem::exists(applicationHome)) { #if defined(__ANDROID__) - __android_log_print(ANDROID_LOG_ERROR, nullptr, + __android_log_print(ANDROID_LOG_ERROR, ANDROID_APPLICATION_ID, "Error: Couldn't create directory, permission problems?"); #else std::cerr << "Error: Couldn't create directory, permission problems?\n"; diff --git a/es-core/src/Log.cpp b/es-core/src/Log.cpp index cacab31ed..b3a4dd149 100644 --- a/es-core/src/Log.cpp +++ b/es-core/src/Log.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // -// EmulationStation Desktop Edition +// ES-DE // Log.cpp // // Log output. @@ -70,7 +70,9 @@ std::ostringstream& Log::get(LogLevel level) localtime_r(&t, &tm); #endif std::unique_lock lock {sLogMutex}; - mOutStringStream << std::put_time(&tm, "%b %d %H:%M:%S ") << mLogLevelMap[level] << ":\t"; + mOutStringStream << std::put_time(&tm, "%b %d %H:%M:%S ") << mLogLevelMap[level] + << (level == LogLevel::LogInfo || level == LogLevel::LogWarning ? ": " : + ": "); mMessageLevel = level; return mOutStringStream; @@ -85,9 +87,10 @@ Log::~Log() // Not open yet, print to stdout. #if defined(__ANDROID__) __android_log_print( - ANDROID_LOG_ERROR, nullptr, + ANDROID_LOG_ERROR, ANDROID_APPLICATION_ID, "Error: Tried to write to log file before it was open, the following won't be logged:"); - __android_log_print(ANDROID_LOG_ERROR, nullptr, "%s", mOutStringStream.str().c_str()); + __android_log_print(ANDROID_LOG_ERROR, ANDROID_APPLICATION_ID, "%s", + mOutStringStream.str().c_str()); #else std::cerr << "Error: Tried to write to log file before it was open, " "the following won't be logged:\n"; @@ -100,15 +103,19 @@ Log::~Log() #if defined(__ANDROID__) if (mMessageLevel == LogError) { - __android_log_print(ANDROID_LOG_ERROR, nullptr, "%s", mOutStringStream.str().c_str()); + __android_log_print(ANDROID_LOG_ERROR, ANDROID_APPLICATION_ID, "%s", + mOutStringStream.str().c_str()); } else if (sReportingLevel >= LogDebug) { if (mMessageLevel == LogInfo) - __android_log_print(ANDROID_LOG_INFO, nullptr, "%s", mOutStringStream.str().c_str()); + __android_log_print(ANDROID_LOG_INFO, ANDROID_APPLICATION_ID, "%s", + mOutStringStream.str().c_str()); else if (mMessageLevel == LogWarning) - __android_log_print(ANDROID_LOG_WARN, nullptr, "%s", mOutStringStream.str().c_str()); + __android_log_print(ANDROID_LOG_WARN, ANDROID_APPLICATION_ID, "%s", + mOutStringStream.str().c_str()); else - __android_log_print(ANDROID_LOG_DEBUG, nullptr, "%s", mOutStringStream.str().c_str()); + __android_log_print(ANDROID_LOG_DEBUG, ANDROID_APPLICATION_ID, "%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. diff --git a/es-core/src/Log.h b/es-core/src/Log.h index 0c9c31528..41e1f1f1c 100644 --- a/es-core/src/Log.h +++ b/es-core/src/Log.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // -// EmulationStation Desktop Edition +// ES-DE // Log.h // // Log output.