Feat/logger (#9)
Some checks are pending
Build ES-DE / Building_RetroDECK-ES-DE (push) Waiting to run

* When RetroDECK is defined the logs are written in the RetroDECK format

* LOG: writing to retrodeck.log if exists and read the log level from retrodeck.cfg

* Added a script to build locally

* LOG: def + include fixes

* LOGS: fixed log folder
This commit is contained in:
XargonWan 2024-11-30 10:00:20 +09:00 committed by GitHub
parent c562a217fc
commit fa2d75af98
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 60 additions and 47 deletions

View file

@ -2,50 +2,4 @@
# WARNING: run this script from the project root folder, not from here!!
# Check if script is running with elevated privileges
if [ "$EUID" -ne 0 ]; then
echo "The build might fail without some superuser permissions, please run me with sudo. Continue without sudo? [y/N]"
read -r continue_without_sudo
if [[ "$continue_without_sudo" != "y" ]]; then
exit 1
fi
fi
git submodule update --init --recursive
export GITHUB_WORKSPACE="."
export FOLDER="es-de-build"
chmod a+rwx -R "$FOLDER"
# Initialize the Flatpak repo
ostree init --mode=archive-z2 --repo=${GITHUB_WORKSPACE}/retrodeck-repo
automation_tools/update_es-de_manifest.sh
cp net.retrodeck.es-de.appdata.xml net.retrodeck.es-de.appdata.xml.bak
cp net.retrodeck.es-de.yml net.retrodeck.es-de.yml.bak
automation_tools/install_dependencies.sh
#automation_tools/cooker_build_id.sh
automation_tools/pre_build_automation.sh
#automation_tools/cooker_flatpak_portal_add.sh
# THIS SCRIPT IS BROKEN HENCE DISABLED FTM
# automation_tools/appdata_management.sh
#automation_tools/flatpak_build_download_only.sh
#automation_tools/flatpak_build_only.sh
#automation_tools/flatpak_build_bundle.sh
flatpak-builder --user --force-clean \
--install-deps-from=flathub \
--install-deps-from=flathub-beta \
--repo="${GITHUB_WORKSPACE}/retrodeck-repo" \
"${GITHUB_WORKSPACE}/${FOLDER}" \
net.retrodeck.es-de.yml
flatpak build-bundle "${GITHUB_WORKSPACE}/retrodeck-repo" "$GITHUB_WORKSPACE/RetroDECK-ES-DE.flatpak" net.retrodeck.es-de
rm -f net.retrodeck.es-de.appdata.xml
rm -f net.retrodeck.es-de.yml
cp net.retrodeck.es-de.appdata.xml.bak net.retrodeck.es-de.appdata.xml
cp net.retrodeck.es-de.yml.bak net.retrodeck.es-de.yml
cmake -DRETRODECK=on -DCMAKE_INSTALL_PREFIX=/app . && make && make install

View file

@ -11,6 +11,10 @@
#include "Settings.h"
#include "utils/StringUtil.h"
#if defined(RETRODECK)
#include <algorithm>
#endif
LogLevel Log::getReportingLevel()
{
std::unique_lock<std::mutex> lock {sLogMutex};
@ -25,10 +29,25 @@ void Log::setReportingLevel(LogLevel level)
void Log::init()
{
#if defined(RETRODECK)
// Check for the rd_logs_folder environment variable
//const char* logFolder = std::getenv("rd_logs_folder");
const char* logFolder = "/var/config/retrodeck/logs";
if (logFolder && std::strlen(logFolder) > 0)
{
sLogPath = std::string(logFolder) + "/retrodeck.log";
}
else
{
// Default to the existing location if rd_logs_folder is not defined
sLogPath = Utils::FileSystem::getAppDataDirectory() + "/retrodeck.log";
}
#else
if (Settings::getInstance()->getBool("LegacyAppDataDirectory"))
sLogPath = Utils::FileSystem::getAppDataDirectory() + "/es_log.txt";
else
sLogPath = Utils::FileSystem::getAppDataDirectory() + "/logs/es_log.txt";
#endif
Utils::FileSystem::removeFile(sLogPath + ".bak");
// Rename the previous log file.
@ -71,9 +90,20 @@ std::ostringstream& Log::get(LogLevel level)
localtime_r(&t, &tm);
#endif
std::unique_lock<std::mutex> lock {sLogMutex};
#if defined(RETRODECK)
// Convert log level to uppercase for RetroDECK
std::string levelUpper = mLogLevelMap[level];
std::transform(levelUpper.begin(), levelUpper.end(), levelUpper.begin(), ::toupper);
mOutStringStream << "[" << std::put_time(&tm, "%Y-%m-%d %H:%M:%S")
<< "] [" << levelUpper << "] [ES-DE] ";
#else
mOutStringStream << std::put_time(&tm, "%b %d %H:%M:%S ") << mLogLevelMap[level]
<< (level == LogLevel::LogInfo || level == LogLevel::LogWarning ? ": " :
": ");
#endif
mMessageLevel = level;
return mOutStringStream;
@ -123,4 +153,29 @@ Log::~Log()
if (mMessageLevel == LogError || sReportingLevel >= LogDebug)
std::cerr << mOutStringStream.str();
#endif
#if defined(RETRODECK)
// Always write logs to the terminal as well when RetroDECK is defined
std::cout << mOutStringStream.str();
#endif
}
// RetroDECK specific function
#if defined(RETRODECK)
void Log::setReportingLevelFromEnv()
{
// Check for the logging_level environment variable
const char* logLevelEnv = std::getenv("logging_level");
std::string logLevel = logLevelEnv ? logLevelEnv : "info";
// Map string to LogLevel
if (logLevel == "debug")
sReportingLevel = LogDebug;
else if (logLevel == "warning")
sReportingLevel = LogWarning;
else if (logLevel == "error")
sReportingLevel = LogError;
else
sReportingLevel = LogInfo; // Default is Info
}
#endif

View file

@ -53,6 +53,10 @@ public:
static void flush();
static void close();
#if defined(RETRODECK)
static void setReportingLevelFromEnv();
#endif
protected:
std::ostringstream mOutStringStream;