From 96decbac27b364e0ffdcb20c40b08a79b827be00 Mon Sep 17 00:00:00 2001 From: Rachel Powers <508861+Ryex@users.noreply.github.com> Date: Mon, 3 Apr 2023 15:14:24 -0700 Subject: [PATCH] feat: default qtlogging.ini file Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com> --- CMakeLists.txt | 4 +++ launcher/Application.cpp | 54 ++++++++++++++++++++++++--------- launcher/Application.h | 5 +++ launcher/CMakeLists.txt | 6 ++++ launcher/qtlogging.ini | 11 +++++++ program_info/win_install.nsi.in | 1 + 6 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 launcher/qtlogging.ini diff --git a/CMakeLists.txt b/CMakeLists.txt index 05c69c893..2ff26aeee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -345,6 +345,8 @@ elseif(UNIX) install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${Launcher_SVG} DESTINATION "${KDE_INSTALL_ICONDIR}/hicolor/scalable/apps") install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${Launcher_mrpack_MIMEInfo} DESTINATION ${KDE_INSTALL_MIMEDIR}) + install(FILES "${CMAKE_CURRENT_SOURCE_DIR}/launcher/qtlogging.ini" DESTINATION "${KDE_INSTALL_DATADIR}/${Launcher_Name}") + if(Launcher_ManPage) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${Launcher_ManPage} DESTINATION "${KDE_INSTALL_MANDIR}/man6") endif() @@ -372,6 +374,8 @@ else() message(FATAL_ERROR "Platform not supported") endif() + + ################################ Included Libs ################################ include(ExternalProject) diff --git a/launcher/Application.cpp b/launcher/Application.cpp index c8855cbc8..f75955123 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -287,6 +287,7 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) if (QFile::exists(FS::PathCombine(m_rootPath, "portable.txt"))) { dataPath = m_rootPath; adjustedBy = "Portable data path"; + m_portable = true; } #endif } @@ -411,25 +412,48 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) " " "|" " " "%{if-category}[%{category}]: %{endif}" "%{message}"); + + bool foundLoggingRules = false; - if(QFile::exists("logging.ini")) { - // load and set logging rules - qDebug() << "Loading logging rules from:" << QString("%1/logging.ini").arg(dataPath); - INIFile loggingRules; - bool rulesLoaded = loggingRules.loadFile(QString("logging.ini")); - if (rulesLoaded) { - QStringList rules; - qDebug() << "Setting log rules:"; - for (auto it = loggingRules.begin(); it != loggingRules.end(); ++it) { - auto rule = it.key() + "=" + it.value().toString(); - rules.append(rule); - qDebug() << " " << rule; - } - auto rules_str = rules.join("\n"); - QLoggingCategory::setFilterRules(rules_str); + auto logRulesFile = QStringLiteral("qtlogging.ini"); + auto logRulesPath = FS::PathCombine(dataPath, logRulesFile); + + qDebug() << "Testing" << logRulesPath << "..."; + foundLoggingRules = QFile::exists(logRulesPath); + + // search the dataPath() + + if(!foundLoggingRules && ! isPortable()) { + logRulesPath = QStandardPaths::locate(QStandardPaths::AppDataLocation, logRulesFile); + if(!logRulesPath.isEmpty()) { + qDebug() << "Found" << logRulesPath << "..."; + foundLoggingRules = true; } } + if(!QFile::exists(logRulesPath)) { + logRulesPath = FS::PathCombine(m_rootPath, logRulesFile); + qDebug() << "Testing" << logRulesPath << "..."; + foundLoggingRules = QFile::exists(logRulesPath); + } + + if(foundLoggingRules) { + // load and set logging rules + qDebug() << "Loading logging rules from:" << logRulesPath; + QSettings loggingRules(logRulesPath, QSettings::IniFormat); + loggingRules.beginGroup("Rules"); + QStringList rule_names = loggingRules.childKeys(); + QStringList rules; + qDebug() << "Setting log rules:"; + for (auto rule_name : rule_names) { + auto rule = QString("%1=%2").arg(rule_name).arg(loggingRules.value(rule_name).toString()); + rules.append(rule); + qDebug() << " " << rule; + } + auto rules_str = rules.join("\n"); + QLoggingCategory::setFilterRules(rules_str); + } + qDebug() << "<> Log initialized."; } diff --git a/launcher/Application.h b/launcher/Application.h index 0d24a4e90..3d833edc3 100644 --- a/launcher/Application.h +++ b/launcher/Application.h @@ -187,6 +187,10 @@ public: return m_rootPath; } + const bool isPortable() { + return m_portable; + } + const Capabilities capabilities() { return m_capabilities; } @@ -275,6 +279,7 @@ private: QString m_rootPath; Status m_status = Application::StartingUp; Capabilities m_capabilities; + bool m_portable = false; #ifdef Q_OS_MACOS Qt::ApplicationState m_prevAppState = Qt::ApplicationInactive; diff --git a/launcher/CMakeLists.txt b/launcher/CMakeLists.txt index 5253a5176..a3ef20e84 100644 --- a/launcher/CMakeLists.txt +++ b/launcher/CMakeLists.txt @@ -1161,6 +1161,12 @@ if(INSTALL_BUNDLE STREQUAL "full") CODE "file(WRITE \"\${CMAKE_INSTALL_PREFIX}/${RESOURCES_DEST_DIR}/qt.conf\" \" \")" COMPONENT Runtime ) + # add qtlogging.ini as a config file + install( + FILES "qtlogging.ini" + DESTINATION ${CMAKE_INSTALL_PREFIX}/${RESOURCES_DEST_DIR} + COMPONENT Runtime + ) # Bundle plugins # Image formats install( diff --git a/launcher/qtlogging.ini b/launcher/qtlogging.ini new file mode 100644 index 000000000..eba5390db --- /dev/null +++ b/launcher/qtlogging.ini @@ -0,0 +1,11 @@ +[Rules] +*.debug=true +# remove the debug lines, other log levels still get through +launcher.task.net.download.debug=false +# enable or disable whole catageries +launcher.task.net=true +launcher.task=false +launcher.task.net.upload=true +launcher.task.net.metacache=false +launcher.task.net.metacache.http=true + diff --git a/program_info/win_install.nsi.in b/program_info/win_install.nsi.in index 49e225007..a809c55dd 100644 --- a/program_info/win_install.nsi.in +++ b/program_info/win_install.nsi.in @@ -282,6 +282,7 @@ Section "@Launcher_DisplayName@" File "@Launcher_APP_BINARY_NAME@.exe" File "qt.conf" + File "qtlogging.ini" File *.dll File /r "iconengines" File /r "imageformats"