diff options
author | Hannah von Reth <hannah.vonreth@owncloud.com> | 2020-09-11 17:17:12 +0300 |
---|---|---|
committer | Hannah von Reth <vonreth@kde.org> | 2020-09-14 22:54:46 +0300 |
commit | b843b4a1d13bbfa0e19995c883d451efb53cf744 (patch) | |
tree | 6451ce860a3c28d96e0f0d16416ce5b4e452e3bd /src | |
parent | 47395ab5a8889953efd665bd5c3f734c1626676a (diff) |
Add option to enable http logging
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/logbrowser.cpp | 9 | ||||
-rw-r--r-- | src/libsync/configfile.cpp | 36 | ||||
-rw-r--r-- | src/libsync/configfile.h | 4 |
3 files changed, 45 insertions, 4 deletions
diff --git a/src/gui/logbrowser.cpp b/src/gui/logbrowser.cpp index 2f24e8296..859abe905 100644 --- a/src/gui/logbrowser.cpp +++ b/src/gui/logbrowser.cpp @@ -68,6 +68,15 @@ LogBrowser::LogBrowser(QWidget *parent) connect(enableLoggingButton, &QCheckBox::toggled, this, &LogBrowser::togglePermanentLogging); mainLayout->addWidget(enableLoggingButton); + auto httpLogButton = new QCheckBox; + // TODO: text? + httpLogButton->setText(tr("Log Http traffic (Warning the logs might contain information about your networks setup)")); + httpLogButton->setChecked(ConfigFile().logHttp()); + connect(httpLogButton, &QCheckBox::toggled, this, [](bool b){ + ConfigFile().setLogHttp(b); + }); + mainLayout->addWidget(httpLogButton); + auto deleteLogsButton = new QCheckBox; deleteLogsButton->setText(tr("Delete logs older than %1 hours").arg(QString::number(defaultExpireDuration.count()))); deleteLogsButton->setChecked(bool(ConfigFile().automaticDeleteOldLogsAge())); diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 9b3d2d515..287885768 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -14,11 +14,11 @@ #include "config.h" -#include "configfile.h" -#include "theme.h" -#include "version.h" #include "common/utility.h" #include "common/asserts.h" +#include "configfile.h" +#include "logger.h" +#include "theme.h" #include "version.h" #include "creds/abstractcredentials.h" @@ -48,7 +48,9 @@ namespace OCC { namespace chrono = std::chrono; Q_LOGGING_CATEGORY(lcConfigFile, "sync.configfile", QtInfoMsg) - +namespace { +const QString logHttpC() { return QStringLiteral("logHttp"); } +} //static const char caCertsKeyC[] = "CaCertificates"; only used from account.cpp static const char remotePollIntervalC[] = "remotePollInterval"; static const char forceSyncIntervalC[] = "forceSyncInterval"; @@ -104,6 +106,7 @@ static chrono::milliseconds millisecondsValue(const QSettings &setting, const ch ConfigFile::ConfigFile() { // QDesktopServices uses the application name to create a config path + // TODO: we use multiple calls to setApplicationName with different arguments... qApp->setApplicationName(Theme::instance()->appNameGUI()); QSettings::setDefaultFormat(QSettings::IniFormat); @@ -113,6 +116,13 @@ ConfigFile::ConfigFile() QSettings settings(config, QSettings::IniFormat); settings.beginGroup(defaultConnection()); + + // run init only once + static bool init = [this]() { + setLogHttp(logHttp()); + return false; + }(); + Q_UNUSED(init); } bool ConfigFile::setConfDir(const QString &value) @@ -800,6 +810,24 @@ void ConfigFile::setAutomaticDeleteOldLogsAge(Optional<chrono::hours> expireTime } } +void ConfigFile::setLogHttp(bool b) +{ + QSettings settings(configFile(), QSettings::IniFormat); + settings.setValue(logHttpC(), b); + const QSet<QString> rule = { QStringLiteral("sync.httplogger=true") }; + if (b) { + Logger::instance()->addLogRule(rule); + } else { + Logger::instance()->removeLogRule(rule); + } +} + +bool ConfigFile::logHttp() const +{ + QSettings settings(configFile(), QSettings::IniFormat); + return settings.value(logHttpC(), false).toBool(); +} + bool ConfigFile::showExperimentalOptions() const { QSettings settings(configFile(), QSettings::IniFormat); diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index 185278b3a..4bf8536b0 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -104,6 +104,10 @@ public: Optional<std::chrono::hours> automaticDeleteOldLogsAge() const; void setAutomaticDeleteOldLogsAge(Optional<std::chrono::hours> expireTime); + /** Whether to log http traffic */ + void setLogHttp(bool b); + bool logHttp() const; + // Whether experimental UI options should be shown bool showExperimentalOptions() const; |