From a8d33099a22c67587f1d4fa7bb18e661e9a282bc Mon Sep 17 00:00:00 2001 From: tobtoht Date: Thu, 3 Mar 2022 16:22:59 +0100 Subject: [PATCH] Settings: add option to disable logging to disk --- src/SettingsDialog.cpp | 5 +++++ src/SettingsDialog.ui | 7 +++++++ src/main.cpp | 11 +++++++++-- src/utils/config.cpp | 2 ++ src/utils/config.h | 2 ++ 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/SettingsDialog.cpp b/src/SettingsDialog.cpp index bb4ffe1..18c27ea 100644 --- a/src/SettingsDialog.cpp +++ b/src/SettingsDialog.cpp @@ -27,6 +27,10 @@ Settings::Settings(QSharedPointer ctx, QWidget *parent) config()->set(Config::hideBalance, toggled); m_ctx->updateBalance(); }); + connect(ui->checkBox_disableLogging, &QCheckBox::toggled, [this](bool toggled){ + config()->set(Config::disableLogging, toggled); + WalletManager::instance()->setLogLevel(toggled ? -1 : config()->get(Config::logLevel).toInt()); + }); connect(ui->closeButton, &QDialogButtonBox::accepted, this, &Settings::close); @@ -39,6 +43,7 @@ Settings::Settings(QSharedPointer ctx, QWidget *parent) ui->checkBox_multiBroadcast->setChecked(config()->get(Config::multiBroadcast).toBool()); ui->checkBox_externalLink->setChecked(config()->get(Config::warnOnExternalLink).toBool()); ui->checkBox_hideBalance->setChecked(config()->get(Config::hideBalance).toBool()); + ui->checkBox_disableLogging->setChecked(config()->get(Config::disableLogging).toBool()); // setup comboboxes this->setupSkinCombobox(); diff --git a/src/SettingsDialog.ui b/src/SettingsDialog.ui index 2a2e152..93b437f 100644 --- a/src/SettingsDialog.ui +++ b/src/SettingsDialog.ui @@ -211,6 +211,13 @@ + + + + Do not write log files to disk + + + diff --git a/src/main.cpp b/src/main.cpp index 531fe90..a534ad1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -143,11 +143,18 @@ if (AttachConsole(ATTACH_PARENT_PROCESS)) { bool logLevelFromEnv; int logLevel = qEnvironmentVariableIntValue("MONERO_LOG_LEVEL", &logLevelFromEnv); + if (!logLevelFromEnv) { + logLevel = 0; + } + config()->set(Config::logLevel, logLevel); - if (parser.isSet("quiet")) + if (parser.isSet("quiet") || config()->get(Config::disableLogging).toBool()) { + qWarning() << "Logging is disabled"; WalletManager::instance()->setLogLevel(-1); - else if (logLevelFromEnv && logLevel >= 0 && logLevel <= Monero::WalletManagerFactory::LogLevel_Max) + } + else if (logLevelFromEnv && logLevel >= 0 && logLevel <= Monero::WalletManagerFactory::LogLevel_Max) { Monero::WalletManagerFactory::setLogLevel(logLevel); + } // Setup wallet directory QString walletDir = config()->get(Config::walletDirectory).toString(); diff --git a/src/utils/config.cpp b/src/utils/config.cpp index 8c693fa..8c39d77 100644 --- a/src/utils/config.cpp +++ b/src/utils/config.cpp @@ -20,6 +20,7 @@ static const QHash configStrings = { {Config::firstRun, {QS("firstRun"), true}}, {Config::warnOnStagenet,{QS("warnOnStagenet"), true}}, {Config::warnOnTestnet,{QS("warnOnTestnet"), true}}, + {Config::logLevel,{QS("logLevel"), 0}}, {Config::homeWidget,{QS("homeWidget"), "ccs"}}, {Config::donateBeg,{QS("donateBeg"), 1}}, @@ -68,6 +69,7 @@ static const QHash configStrings = { {Config::multiBroadcast, {QS("multiBroadcast"), true}}, {Config::warnOnExternalLink,{QS("warnOnExternalLink"), true}}, {Config::hideBalance, {QS("hideBalance"), false}}, + {Config::disableLogging, {QS("disableLogging"), false}}, {Config::blockExplorer,{QS("blockExplorer"), "exploremonero.com"}}, {Config::redditFrontend, {QS("redditFrontend"), "old.reddit.com"}}, diff --git a/src/utils/config.h b/src/utils/config.h index f0fd70e..3d1f19f 100644 --- a/src/utils/config.h +++ b/src/utils/config.h @@ -24,6 +24,7 @@ public: firstRun, warnOnStagenet, warnOnTestnet, + logLevel, homeWidget, donateBeg, @@ -72,6 +73,7 @@ public: multiBroadcast, warnOnExternalLink, hideBalance, + disableLogging, blockExplorer, redditFrontend,