Skip to content

Commit 5c6c0b4

Browse files
committed
feat(logging): implement logging level configuration from RetroDECK settings
1 parent eb42a6c commit 5c6c0b4

File tree

5 files changed

+130
-18
lines changed

5 files changed

+130
-18
lines changed

es-app/src/guis/GuiMenu.cpp

Lines changed: 54 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,25 +2663,64 @@ void GuiMenu::openRetroDeckGodotConfigurator()
26632663
// You can add any checks for the script's outcome here.
26642664
}
26652665

2666-
#endif
2667-
2668-
#if defined(RETRODECK)
26692666
void GuiMenu::openESDEConfiguration()
26702667
{
26712668
auto s = new GuiSettings(_("ES-DE CONFIGURATIONS"));
26722669

2673-
// Logging level setting for RetroDECK
2674-
auto loggingLevel = std::make_shared<OptionListComponent<std::string>>(_("LOGGING LEVEL"), false);
2675-
loggingLevel->add(_("DEBUG"), "debug", Settings::getInstance()->getString("LoggingLevel") == "debug");
2676-
loggingLevel->add(_("INFO"), "info", Settings::getInstance()->getString("LoggingLevel") == "info");
2677-
loggingLevel->add(_("WARNING"), "warning", Settings::getInstance()->getString("LoggingLevel") == "warning");
2678-
loggingLevel->add(_("ERROR"), "error", Settings::getInstance()->getString("LoggingLevel") == "error");
2679-
s->addWithLabel(_("LOGGING LEVEL"), loggingLevel);
2680-
s->addSaveFunc([loggingLevel] {
2681-
Settings::getInstance()->setString("LoggingLevel", loggingLevel->getSelected());
2682-
Settings::getInstance()->saveFile();
2683-
Log::setReportingLevelFromEnv(); // Assuming this function exists to update logging level
2684-
});
2670+
// UI Settings submenu
2671+
ComponentListRow uiSettingsRow;
2672+
uiSettingsRow.elements.clear();
2673+
uiSettingsRow.addElement(std::make_shared<TextComponent>(_("UI SETTINGS"),
2674+
Font::get(FONT_SIZE_MEDIUM),
2675+
mMenuColorPrimary),
2676+
true);
2677+
uiSettingsRow.addElement(mMenu.makeArrow(), false);
2678+
uiSettingsRow.makeAcceptInputHandler(std::bind(&GuiMenu::openUIOptions, this));
2679+
s->addRow(uiSettingsRow);
2680+
2681+
// Sound Settings submenu
2682+
ComponentListRow soundSettingsRow;
2683+
soundSettingsRow.elements.clear();
2684+
soundSettingsRow.addElement(std::make_shared<TextComponent>(_("SOUND SETTINGS"),
2685+
Font::get(FONT_SIZE_MEDIUM),
2686+
mMenuColorPrimary),
2687+
true);
2688+
soundSettingsRow.addElement(mMenu.makeArrow(), false);
2689+
soundSettingsRow.makeAcceptInputHandler(std::bind(&GuiMenu::openSoundOptions, this));
2690+
s->addRow(soundSettingsRow);
2691+
2692+
// Input Device Settings submenu
2693+
ComponentListRow inputDeviceSettingsRow;
2694+
inputDeviceSettingsRow.elements.clear();
2695+
inputDeviceSettingsRow.addElement(std::make_shared<TextComponent>(_("INPUT DEVICE SETTINGS"),
2696+
Font::get(FONT_SIZE_MEDIUM),
2697+
mMenuColorPrimary),
2698+
true);
2699+
inputDeviceSettingsRow.addElement(mMenu.makeArrow(), false);
2700+
inputDeviceSettingsRow.makeAcceptInputHandler(std::bind(&GuiMenu::openInputDeviceOptions, this));
2701+
s->addRow(inputDeviceSettingsRow);
2702+
2703+
// Game Collection Settings submenu
2704+
ComponentListRow collectionSettingsRow;
2705+
collectionSettingsRow.elements.clear();
2706+
collectionSettingsRow.addElement(std::make_shared<TextComponent>(_("GAME COLLECTION SETTINGS"),
2707+
Font::get(FONT_SIZE_MEDIUM),
2708+
mMenuColorPrimary),
2709+
true);
2710+
collectionSettingsRow.addElement(mMenu.makeArrow(), false);
2711+
collectionSettingsRow.makeAcceptInputHandler(std::bind(&GuiMenu::openCollectionSystemOptions, this));
2712+
s->addRow(collectionSettingsRow);
2713+
2714+
// Other Settings submenu
2715+
ComponentListRow otherSettingsRow;
2716+
otherSettingsRow.elements.clear();
2717+
otherSettingsRow.addElement(std::make_shared<TextComponent>(_("OTHER SETTINGS"),
2718+
Font::get(FONT_SIZE_MEDIUM),
2719+
mMenuColorPrimary),
2720+
true);
2721+
otherSettingsRow.addElement(mMenu.makeArrow(), false);
2722+
otherSettingsRow.makeAcceptInputHandler(std::bind(&GuiMenu::openOtherOptions, this));
2723+
s->addRow(otherSettingsRow);
26852724

26862725
mWindow->pushGui(s);
26872726
}

es-app/src/main.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,12 @@ int main(int argc, char* argv[])
715715
// Start the logger.
716716
Log::init();
717717
Log::open();
718+
719+
#if defined(RETRODECK)
720+
// Set logging level from RetroDECK configuration file.
721+
Log::setReportingLevelFromRetroDeckConfig();
722+
#endif
723+
718724
{
719725
const std::string applicationName {"ES-DE"};
720726
#if defined(__ANDROID__)

es-core/src/Log.cpp

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
#if defined(RETRODECK)
1515
#include <algorithm>
16+
#include <fstream>
1617
#endif
1718

1819
LogLevel Log::getReportingLevel()
@@ -183,6 +184,74 @@ Log::~Log()
183184

184185
// RetroDECK specific function
185186
#if defined(RETRODECK)
187+
void Log::setReportingLevelFromRetroDeckConfig()
188+
{
189+
// Try to read the logging level from RetroDECK config file
190+
const char* rdHomePath = std::getenv("RETRODECK_CONFIG_HOME");
191+
if (!rdHomePath) {
192+
LOG(LogError) << "setReportingLevelFromRetroDeckConfig: Failed to read rd_logging_level "
193+
<< "- RETRODECK_CONFIG_HOME environment variable not set. Falling back to DEBUG.";
194+
sReportingLevel = LogDebug;
195+
return;
196+
}
197+
198+
std::string configPath = std::string(rdHomePath) + "/retrodeck.cfg";
199+
std::ifstream configFile(configPath);
200+
if (!configFile.is_open()) {
201+
LOG(LogError) << "setReportingLevelFromRetroDeckConfig: Failed to read rd_logging_level "
202+
<< "from '" << configPath << "' - File not found. Falling back to DEBUG.";
203+
sReportingLevel = LogDebug;
204+
return;
205+
}
206+
207+
// Parse the JSON file looking for rd_logging_level
208+
std::string line;
209+
std::string logLevel = "debug"; // Default fallback
210+
bool found = false;
211+
212+
while (std::getline(configFile, line)) {
213+
// Simple pattern matching for "rd_logging_level": "value"
214+
size_t pos = line.find("\"rd_logging_level\"");
215+
if (pos != std::string::npos) {
216+
// Find the value between quotes after the colon
217+
size_t colonPos = line.find(':', pos);
218+
if (colonPos != std::string::npos) {
219+
size_t firstQuote = line.find('"', colonPos);
220+
size_t secondQuote = line.find('"', firstQuote + 1);
221+
if (firstQuote != std::string::npos && secondQuote != std::string::npos) {
222+
logLevel = line.substr(firstQuote + 1, secondQuote - firstQuote - 1);
223+
found = true;
224+
break;
225+
}
226+
}
227+
}
228+
}
229+
230+
configFile.close();
231+
232+
if (!found) {
233+
LOG(LogError) << "setReportingLevelFromRetroDeckConfig: Failed to read rd_logging_level "
234+
<< "from '" << configPath << "' - Setting not found. Falling back to DEBUG.";
235+
sReportingLevel = LogDebug;
236+
return;
237+
}
238+
239+
// Map string to LogLevel
240+
if (logLevel == "debug")
241+
sReportingLevel = LogDebug;
242+
else if (logLevel == "warning")
243+
sReportingLevel = LogWarning;
244+
else if (logLevel == "error")
245+
sReportingLevel = LogError;
246+
else if (logLevel == "info")
247+
sReportingLevel = LogInfo;
248+
else {
249+
LOG(LogError) << "setReportingLevelFromRetroDeckConfig: Invalid rd_logging_level value '"
250+
<< logLevel << "'. Falling back to DEBUG.";
251+
sReportingLevel = LogDebug;
252+
}
253+
}
254+
186255
void Log::setReportingLevelFromEnv()
187256
{
188257
// Check for the logging_level environment variable

es-core/src/Log.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class Log
5454
static void close();
5555

5656
#if defined(RETRODECK)
57+
static void setReportingLevelFromRetroDeckConfig();
5758
static void setReportingLevelFromEnv();
5859
#endif
5960

es-core/src/Settings.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,9 +179,6 @@ void Settings::setDefaults()
179179
mStringMap["LaunchScreenDuration"] = {"normal", "normal"};
180180
mStringMap["UIMode"] = {"full", "full"};
181181
mStringMap["RandomEntryButton"] = {"games", "games"};
182-
#if defined(RETRODECK)
183-
mStringMap["LoggingLevel"] = {"info", "info"};
184-
#endif
185182

186183
// UI settings -> system status settings.
187184
mBoolMap["SystemStatusBluetooth"] = {true, true};

0 commit comments

Comments
 (0)