feat: add new setting Log::GuiDebug to control when the Gui shows debug messages no longer controled by an ENV var
This commit is contained in:
@ -802,24 +802,3 @@ section: links
|
||||
down = larry
|
||||
end
|
||||
```
|
||||
|
||||
# Example `.env` file
|
||||
|
||||
|
||||
```
|
||||
#
|
||||
# App
|
||||
#
|
||||
|
||||
# Shows the test menu in the GUI (on by default in debug mode)
|
||||
# DESKFLOW_TEST_MENU=true
|
||||
|
||||
# Version checker URL to use (useful for testing)
|
||||
# DESKFLOW_VERSION_URL="https://api.deskflow.org/version?fake=1.100.0"
|
||||
|
||||
# Enable debug logging in the GUI (on by default in debug mode)
|
||||
# DESKFLOW_GUI_DEBUG=true
|
||||
|
||||
# Enable verbose logging in the GUI (always off by default)
|
||||
# DESKFLOW_GUI_VERBOSE=true
|
||||
```
|
||||
|
||||
@ -133,7 +133,6 @@ int main(int argc, char *argv[])
|
||||
qInfo("%s v%s", kAppName, kDisplayVersion);
|
||||
|
||||
dotenv();
|
||||
Logger::instance()->loadEnvVars();
|
||||
|
||||
#if defined(Q_OS_MAC)
|
||||
|
||||
|
||||
@ -78,6 +78,7 @@ public:
|
||||
inline static const auto File = QStringLiteral("log/file");
|
||||
inline static const auto Level = QStringLiteral("log/level");
|
||||
inline static const auto ToFile = QStringLiteral("log/toFile");
|
||||
inline static const auto GuiDebug = QStringLiteral("log/guiDebug");
|
||||
};
|
||||
struct Security
|
||||
{
|
||||
@ -185,6 +186,7 @@ private:
|
||||
, Settings::Log::File
|
||||
, Settings::Log::Level
|
||||
, Settings::Log::ToFile
|
||||
, Settings::Log::GuiDebug
|
||||
, Settings::Gui::Autohide
|
||||
, Settings::Gui::AutoUpdateCheck
|
||||
, Settings::Gui::CloseReminder
|
||||
@ -209,6 +211,7 @@ private:
|
||||
, Settings::Server::ExternalConfig
|
||||
, Settings::Client::InvertScrollDirection
|
||||
, Settings::Log::ToFile
|
||||
, Settings::Log::GuiDebug
|
||||
};
|
||||
|
||||
// When checking the default values this list contains the ones that default to true.
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
*/
|
||||
|
||||
#include "Logger.h"
|
||||
#include "common/Settings.h"
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QDir>
|
||||
@ -49,14 +50,8 @@ QString printLine(FILE *out, const QString &type, const QString &message, const
|
||||
return logLine;
|
||||
}
|
||||
|
||||
void Logger::loadEnvVars()
|
||||
{
|
||||
m_debug = QVariant(qEnvironmentVariable("DESKFLOW_GUI_DEBUG")).toBool();
|
||||
}
|
||||
|
||||
void Logger::handleMessage(const QtMsgType type, const QString &fileLine, const QString &message)
|
||||
{
|
||||
|
||||
auto mutatedType = type;
|
||||
if (kForceDebugMessages.contains(message)) {
|
||||
mutatedType = QtDebugMsg;
|
||||
@ -66,10 +61,9 @@ void Logger::handleMessage(const QtMsgType type, const QString &fileLine, const
|
||||
auto out = stdout;
|
||||
switch (mutatedType) {
|
||||
case QtDebugMsg:
|
||||
typeString = "DEBUG";
|
||||
if (!m_debug) {
|
||||
if (!Settings::value(Settings::Log::GuiDebug).toBool())
|
||||
return;
|
||||
}
|
||||
typeString = "DEBUG";
|
||||
break;
|
||||
case QtInfoMsg:
|
||||
typeString = "INFO";
|
||||
|
||||
@ -21,18 +21,10 @@ public:
|
||||
return &m;
|
||||
}
|
||||
|
||||
void loadEnvVars();
|
||||
void handleMessage(const QtMsgType type, const QString &fileLine, const QString &message);
|
||||
|
||||
Q_SIGNALS:
|
||||
void newLine(const QString &line);
|
||||
|
||||
private:
|
||||
#ifdef NDEBUG
|
||||
bool m_debug = false;
|
||||
#else
|
||||
bool m_debug = true;
|
||||
#endif
|
||||
};
|
||||
|
||||
} // namespace deskflow::gui
|
||||
|
||||
@ -177,6 +177,7 @@ void SettingsDialog::accept()
|
||||
Settings::setValue(Settings::Security::CheckPeers, ui->cbRequireClientCert->isChecked());
|
||||
Settings::setValue(Settings::Client::ScrollSpeed, ui->sbScrollSpeed->value());
|
||||
Settings::setValue(Settings::Core::Language, ui->comboLanguage->currentText());
|
||||
Settings::setValue(Settings::Log::GuiDebug, ui->cbGuiDebug->isChecked());
|
||||
|
||||
Settings::ProcessMode mode;
|
||||
if (ui->groupService->isChecked())
|
||||
@ -203,6 +204,7 @@ void SettingsDialog::loadFromConfig()
|
||||
ui->cbElevateDaemon->setChecked(Settings::value(Settings::Daemon::Elevate).toBool());
|
||||
ui->cbAutoUpdate->setChecked(Settings::value(Settings::Gui::AutoUpdateCheck).toBool());
|
||||
ui->sbScrollSpeed->setValue(Settings::value(Settings::Client::ScrollSpeed).toInt());
|
||||
ui->cbGuiDebug->setChecked(Settings::value(Settings::Log::GuiDebug).toBool());
|
||||
|
||||
const auto processMode = Settings::value(Settings::Core::ProcessMode).value<Settings::ProcessMode>();
|
||||
ui->groupService->setChecked(processMode == Settings::ProcessMode::Service);
|
||||
|
||||
@ -417,7 +417,64 @@
|
||||
<property name="verticalSpacing">
|
||||
<number>9</number>
|
||||
</property>
|
||||
<item row="7" column="0" colspan="4">
|
||||
<item row="3" column="2">
|
||||
<widget class="QLabel" name="lblLogLevel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Level</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="3">
|
||||
<widget class="QComboBox" name="comboLogLevel">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Fatal</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Error</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Warning</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Note</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Info</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Debug</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Debug1</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Debug2</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0" colspan="4">
|
||||
<widget class="QWidget" name="widgetLogFilename" native="true">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Maximum">
|
||||
@ -505,7 +562,14 @@
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<item row="3" column="0">
|
||||
<widget class="QCheckBox" name="cbLogToFile">
|
||||
<property name="text">
|
||||
<string>Log to file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<spacer name="horizontalSpacer_5">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Orientation::Horizontal</enum>
|
||||
@ -518,71 +582,7 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QCheckBox" name="cbLogToFile">
|
||||
<property name="text">
|
||||
<string>Log to file</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="3">
|
||||
<widget class="QComboBox" name="comboLogLevel">
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Fatal</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Error</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Warning</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Note</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Info</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Debug</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Debug1</string>
|
||||
</property>
|
||||
</item>
|
||||
<item>
|
||||
<property name="text">
|
||||
<string>Debug2</string>
|
||||
</property>
|
||||
</item>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="2">
|
||||
<widget class="QLabel" name="lblLogLevel">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Level</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="8" column="0" colspan="4">
|
||||
<item row="9" column="0" colspan="4">
|
||||
<widget class="QLabel" name="lblDebugWarning">
|
||||
<property name="text">
|
||||
<string>Using a Debug log level may affect performance. Only use a Debug level if you are attempting to debug an issue or are gathering logs to submit with a bug report.</string>
|
||||
@ -592,6 +592,13 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0" colspan="4">
|
||||
<widget class="QCheckBox" name="cbGuiDebug">
|
||||
<property name="text">
|
||||
<string>Enable GUI debug messages</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
|
||||
@ -6,13 +6,28 @@
|
||||
*/
|
||||
|
||||
#include "LoggerTests.h"
|
||||
#include "common/Settings.h"
|
||||
|
||||
#include "gui/Logger.h"
|
||||
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
#include <QSignalSpy>
|
||||
|
||||
using namespace deskflow::gui;
|
||||
|
||||
void LoggerTests::initTestCase()
|
||||
{
|
||||
QDir dir;
|
||||
QVERIFY(dir.mkpath(m_settingsPath));
|
||||
|
||||
QFile oldSettings(m_settingsFile);
|
||||
if (oldSettings.exists())
|
||||
oldSettings.remove();
|
||||
|
||||
Settings::setSettingsFile(m_settingsFile);
|
||||
}
|
||||
|
||||
void LoggerTests::newLine()
|
||||
{
|
||||
Logger logger;
|
||||
@ -20,14 +35,12 @@ void LoggerTests::newLine()
|
||||
QSignalSpy spy(&logger, &Logger::newLine);
|
||||
QVERIFY(spy.isValid());
|
||||
|
||||
qputenv("DESKFLOW_GUI_DEBUG", "true");
|
||||
logger.loadEnvVars();
|
||||
|
||||
Settings::setValue(Settings::Log::GuiDebug, true);
|
||||
logger.handleMessage(QtDebugMsg, "stub", "test");
|
||||
|
||||
QCOMPARE(spy.count(), 1);
|
||||
QVERIFY(qvariant_cast<QString>(spy.takeFirst().at(0)).contains("test"));
|
||||
qputenv("DESKFLOW_GUI_DEBUG", "");
|
||||
Settings::setValue(Settings::Log::GuiDebug, false);
|
||||
}
|
||||
|
||||
void LoggerTests::noNewLine()
|
||||
@ -38,12 +51,10 @@ void LoggerTests::noNewLine()
|
||||
QSignalSpy spy(&logger, &Logger::newLine);
|
||||
QVERIFY(spy.isValid());
|
||||
|
||||
qputenv("DESKFLOW_GUI_DEBUG", "false");
|
||||
logger.loadEnvVars();
|
||||
Settings::setValue(Settings::Log::GuiDebug, false);
|
||||
logger.handleMessage(QtDebugMsg, "stub", "test");
|
||||
QCOMPARE(spy.count(), 0);
|
||||
QVERIFY(!newLineEmitted);
|
||||
qputenv("DESKFLOW_GUI_DEBUG", "");
|
||||
}
|
||||
|
||||
QTEST_MAIN(LoggerTests)
|
||||
|
||||
@ -11,6 +11,11 @@ class LoggerTests : public QObject
|
||||
Q_OBJECT
|
||||
private Q_SLOTS:
|
||||
// Test are run in order top to bottom
|
||||
void initTestCase();
|
||||
void newLine();
|
||||
void noNewLine();
|
||||
|
||||
private:
|
||||
inline static const QString m_settingsPath = QStringLiteral("tmp/test");
|
||||
inline static const QString m_settingsFile = QStringLiteral("%1/Deskflow.conf").arg(m_settingsPath);
|
||||
};
|
||||
|
||||
@ -1235,6 +1235,10 @@ Al habilitar esta opción, se deshabilitará la interfaz gráfica de usuario (GU
|
||||
<source>Force a language to be used for the GUI.</source>
|
||||
<translation type="unfinished">Fuerza el uso de un idioma para la interfaz gráfica de usuario.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Enable GUI debug messages</source>
|
||||
<translation type="unfinished">Habilitar mensajes de depuración de la interfaz gráfica de usuario</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>TlsCertificate</name>
|
||||
|
||||
@ -1235,6 +1235,10 @@ L'abilitazione di questa impostazione disabiliterà l'interfaccia graf
|
||||
<source>Force a language to be used for the GUI.</source>
|
||||
<translation>Forza l'utilizzo di una lingua per la GUI.</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Enable GUI debug messages</source>
|
||||
<translation>Abilita i messaggi di debug della GUI</translation>
|
||||
</message>
|
||||
</context>
|
||||
<context>
|
||||
<name>TlsCertificate</name>
|
||||
|
||||
Reference in New Issue
Block a user