(Android) Added the application ID to the log output

Also changed the general log output formatting slightly
This commit is contained in:
Leon Styhre 2023-11-27 20:19:35 +01:00
parent b2e9507b0e
commit 84534cf5d7
4 changed files with 23 additions and 20 deletions

View file

@ -286,6 +286,7 @@ endif()
if(ANDROID)
set(BUNDLED_CERTS ON)
add_compile_definitions(ANDROID_APPLICATION_ID="org.es_de.frontend")
endif()
if(WIN32)

View file

@ -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";

View file

@ -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<std::mutex> 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.

View file

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT
//
// EmulationStation Desktop Edition
// ES-DE
// Log.h
//
// Log output.