summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-11-22 07:44:09 -0500
committerisanae <14251494+isanae@users.noreply.github.com>2019-11-22 07:44:09 -0500
commit8fcaea9de32b888ec8839ef6b7f394556383275e (patch)
tree98996aedaf69902251328f8598c9670d27199cbc
parent2b5747c19d942974295be18042fbdde8ddc4cc78 (diff)
added loot log level option
-rw-r--r--src/loot.cpp79
-rw-r--r--src/settings.cpp11
-rw-r--r--src/settings.h5
-rw-r--r--src/settingsdialog.ui136
-rw-r--r--src/settingsdialogdiagnostics.cpp36
-rw-r--r--src/settingsdialogdiagnostics.h3
6 files changed, 164 insertions, 106 deletions
diff --git a/src/loot.cpp b/src/loot.cpp
index 7184cce8..c5df8c9d 100644
--- a/src/loot.cpp
+++ b/src/loot.cpp
@@ -6,6 +6,30 @@
using namespace MOBase;
+log::Levels levelFromLoot(lootcli::LogLevels level)
+{
+ using LC = lootcli::LogLevels;
+
+ switch (level)
+ {
+ case LC::Trace: // fall-through
+ case LC::Debug:
+ return log::Debug;
+
+ case LC::Info:
+ return log::Info;
+
+ case LC::Warning:
+ return log::Warning;
+
+ case LC::Error:
+ return log::Error;
+
+ default:
+ return log::Info;
+ }
+}
+
class LootDialog : public QDialog
{
@@ -15,6 +39,7 @@ public:
m_label(nullptr), m_progress(nullptr), m_buttons(nullptr), m_finished(false)
{
createUI();
+ m_progress->setMaximum(0);
QObject::connect(
&m_loot, &Loot::output, this,
@@ -45,6 +70,11 @@ public:
void setProgress(lootcli::Progress p)
{
setText(progressToString(p));
+
+ if (p == lootcli::Progress::Done) {
+ m_progress->setRange(0, 1);
+ m_progress->setValue(1);
+ }
}
QString progressToString(lootcli::Progress p)
@@ -65,13 +95,12 @@ public:
}
}
- void setIndeterminate()
- {
- m_progress->setMaximum(0);
- }
-
void addOutput(const QString& s)
{
+ if (m_core.settings().diagnostics().lootLogLevel() > lootcli::LogLevels::Debug) {
+ return;
+ }
+
const auto lines = s.split(QRegExp("[\\r\\n]"), QString::SkipEmptyParts);
for (auto&& line : lines) {
@@ -101,17 +130,7 @@ public:
int exec() override
{
- QDialog::exec();
-
- if (m_errorMessages.length() > 0) {
- QMessageBox *warn = new QMessageBox(
- QMessageBox::Warning, tr("Errors occurred"),
- m_errorMessages, QMessageBox::Ok, parentWidget());
-
- warn->exec();
- }
-
- return 0;
+ return QDialog::exec();
}
void onError(const QString& s)
@@ -126,8 +145,6 @@ private:
QProgressBar* m_progress;
QDialogButtonBox* m_buttons;
QPlainTextEdit* m_output;
- QString m_lastLine;
- QString m_errorMessages;
bool m_finished;
void createUI()
@@ -146,11 +163,14 @@ private:
ly->addWidget(m_progress);
m_output = new QPlainTextEdit;
+ m_output->setWordWrapMode(QTextOption::NoWrap);
ly->addWidget(m_output);
m_buttons = new QDialogButtonBox(QDialogButtonBox::Cancel);
connect(m_buttons, &QDialogButtonBox::clicked, [&](auto* b){ onButton(b); });
ly->addWidget(m_buttons);
+
+ resize(700, 400);
}
void closeEvent(QCloseEvent* e) override
@@ -173,7 +193,6 @@ private:
void addLineOutput(const QString& line)
{
m_output->appendPlainText(line);
- m_lastLine = line;
}
void onFinished()
@@ -183,14 +202,12 @@ private:
void log(log::Levels lv, const QString& s)
{
- if (lv == log::Levels::Error) {
- MOBase::log::error("{}", s);
-
- if (!m_errorMessages.isEmpty()) {
- m_errorMessages += "\n";
- }
+ if (lv >= log::Levels::Warning) {
+ log::log(lv, "{}", s);
+ }
- m_errorMessages += s;
+ if (m_core.settings().diagnostics().lootLogLevel() > lootcli::LogLevels::Debug) {
+ addLineOutput(QString("[%1] %2").arg(log::levelToString(lv)).arg(s));
}
}
};
@@ -210,11 +227,14 @@ bool Loot::start(QWidget* parent, OrganizerCore& core, bool didUpdateMasterList)
{
m_outPath = QDir::temp().absoluteFilePath("lootreport.json");
+ const auto logLevel = core.settings().diagnostics().lootLogLevel();
+
QStringList parameters;
parameters
<< "--game" << core.managedGame()->gameShortName()
<< "--gamePath" << QString("\"%1\"").arg(core.managedGame()->gameDirectory().absolutePath())
<< "--pluginListPath" << QString("\"%1/loadorder.txt\"").arg(core.profilePath())
+ << "--logLevel" << QString::fromStdString(lootcli::logLevelToString(logLevel))
<< "--out" << QString("\"%1\"").arg(m_outPath);
if (didUpdateMasterList) {
@@ -406,7 +426,7 @@ void Loot::processMessage(const lootcli::Message& m)
{
case lootcli::MessageType::Log:
{
- if (m.logLevel == spdlog::level::err) {
+ if (m.logLevel == lootcli::LogLevels::Error) {
std::smatch match;
if (std::regex_match(m.log, match, exRequires)) {
@@ -422,10 +442,10 @@ void Loot::processMessage(const lootcli::Message& m)
QString::fromStdString(modName),
tr("incompatible with \"%1\"").arg(dependency.c_str()));
} else {
- emit log(log::levelFromSpdlog(m.logLevel), QString::fromStdString(m.log));
+ emit log(levelFromLoot(m.logLevel), QString::fromStdString(m.log));
}
} else {
- emit log(log::levelFromSpdlog(m.logLevel), QString::fromStdString(m.log));
+ emit log(levelFromLoot(m.logLevel), QString::fromStdString(m.log));
}
break;
@@ -657,7 +677,6 @@ bool runLoot(QWidget* parent, OrganizerCore& core, bool didUpdateMasterList)
loot.start(parent, core, didUpdateMasterList);
dialog.setText(QObject::tr("Please wait while LOOT is running"));
- dialog.setIndeterminate();
dialog.exec();
return dialog.result();
diff --git a/src/settings.cpp b/src/settings.cpp
index 5aeb82fe..b533b400 100644
--- a/src/settings.cpp
+++ b/src/settings.cpp
@@ -1977,6 +1977,17 @@ void DiagnosticsSettings::setLogLevel(log::Levels level)
set(m_Settings, "Settings", "log_level", level);
}
+lootcli::LogLevels DiagnosticsSettings::lootLogLevel() const
+{
+ return get<lootcli::LogLevels>(
+ m_Settings, "Settings", "loot_log_level", lootcli::LogLevels::Info);
+}
+
+void DiagnosticsSettings::setLootLogLevel(lootcli::LogLevels level)
+{
+ set(m_Settings, "Settings", "loot_log_level", level);
+}
+
CrashDumpsType DiagnosticsSettings::crashDumpsType() const
{
return get<CrashDumpsType>(m_Settings,
diff --git a/src/settings.h b/src/settings.h
index d604823a..d71fabf4 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -21,6 +21,7 @@ along with Mod Organizer. If not, see <http://www.gnu.org/licenses/>.
#define SETTINGS_H
#include "loadmechanism.h"
+#include <lootcli/lootcli.h>
#include <questionboxmemory.h>
#include <log.h>
#include <usvfsparameters.h>
@@ -619,6 +620,10 @@ public:
MOBase::log::Levels logLevel() const;
void setLogLevel(MOBase::log::Levels level);
+ // log level for loot
+ lootcli::LogLevels lootLogLevel() const;
+ void setLootLogLevel(lootcli::LogLevels level);
+
// crash dump type for both MO and usvfs
//
CrashDumpsType crashDumpsType() const;
diff --git a/src/settingsdialog.ui b/src/settingsdialog.ui
index 0ecbd101..b88c8b71 100644
--- a/src/settingsdialog.ui
+++ b/src/settingsdialog.ui
@@ -1386,44 +1386,23 @@ programs you are intentionally running.</string>
<string>Diagnostics</string>
</attribute>
<layout class="QGridLayout" name="gridLayout_4">
- <item row="2" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout_13">
- <item>
- <widget class="QLabel" name="label_28">
- <property name="text">
- <string>Max Dumps To Keep</string>
- </property>
- </widget>
- </item>
- <item>
- <spacer name="horizontalSpacer_6">
- <property name="orientation">
- <enum>Qt::Horizontal</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>60</width>
- <height>20</height>
- </size>
- </property>
- </spacer>
- </item>
- <item>
- <widget class="QSpinBox" name="dumpsMaxEdit">
- <property name="toolTip">
- <string>Maximum number of crash dumps to keep on disk. Use 0 for unlimited.</string>
- </property>
- <property name="whatsThis">
- <string>
- Maximum number of crash dumps to keep on disk. Use 0 for unlimited.
- Set &quot;Crash Dumps&quot; above to None to disable crash dump collection.
- </string>
- </property>
- </widget>
- </item>
- </layout>
- </item>
<item row="3" column="0">
+ <spacer name="verticalSpacer_10">
+ <property name="orientation">
+ <enum>Qt::Vertical</enum>
+ </property>
+ <property name="sizeType">
+ <enum>QSizePolicy::Expanding</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>20</width>
+ <height>232</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="2" column="0">
<widget class="QLabel" name="diagnosticsExplainedLabel">
<property name="toolTip">
<string>Hint: right click link and copy link location</string>
@@ -1444,16 +1423,42 @@ programs you are intentionally running.</string>
</property>
</widget>
</item>
- <item row="1" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout_12">
- <item>
+ <item row="0" column="0">
+ <layout class="QFormLayout" name="formLayout_5">
+ <property name="fieldGrowthPolicy">
+ <enum>QFormLayout::ExpandingFieldsGrow</enum>
+ </property>
+ <property name="horizontalSpacing">
+ <number>12</number>
+ </property>
+ <item row="0" column="0">
+ <widget class="QLabel" name="label_12">
+ <property name="text">
+ <string>Log Level</string>
+ </property>
+ </widget>
+ </item>
+ <item row="0" column="1">
+ <widget class="QComboBox" name="logLevelBox">
+ <property name="toolTip">
+ <string>Decides the amount of data printed to &quot;ModOrganizer.log&quot;</string>
+ </property>
+ <property name="whatsThis">
+ <string>
+ Decides the amount of data printed to &quot;ModOrganizer.log&quot;.
+ &quot;Debug&quot; produces very useful information for finding problems. There is usually no noteworthy performance impact but the file may become rather large. If this is a problem you may prefer the &quot;Info&quot; level for regular use. On the &quot;Error&quot; level the log file usually remains empty.
+ </string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="0">
<widget class="QLabel" name="label_27">
<property name="text">
<string>Crash Dumps</string>
</property>
</widget>
</item>
- <item>
+ <item row="1" column="1">
<widget class="QComboBox" name="dumpsTypeBox">
<property name="toolTip">
<string>Decides which type of crash dumps are collected when injected processes crash.</string>
@@ -1469,46 +1474,36 @@ programs you are intentionally running.</string>
</property>
</widget>
</item>
- </layout>
- </item>
- <item row="4" column="0">
- <spacer name="verticalSpacer_10">
- <property name="orientation">
- <enum>Qt::Vertical</enum>
- </property>
- <property name="sizeType">
- <enum>QSizePolicy::Expanding</enum>
- </property>
- <property name="sizeHint" stdset="0">
- <size>
- <width>20</width>
- <height>232</height>
- </size>
- </property>
- </spacer>
- </item>
- <item row="0" column="0">
- <layout class="QHBoxLayout" name="horizontalLayout_6">
- <item>
- <widget class="QLabel" name="label_12">
+ <item row="2" column="0">
+ <widget class="QLabel" name="label_28">
<property name="text">
- <string>Log Level</string>
+ <string>Max Dumps To Keep</string>
</property>
</widget>
</item>
- <item>
- <widget class="QComboBox" name="logLevelBox">
+ <item row="2" column="1">
+ <widget class="QSpinBox" name="dumpsMaxEdit">
<property name="toolTip">
- <string>Decides the amount of data printed to &quot;ModOrganizer.log&quot;</string>
+ <string>Maximum number of crash dumps to keep on disk. Use 0 for unlimited.</string>
</property>
<property name="whatsThis">
<string>
- Decides the amount of data printed to &quot;ModOrganizer.log&quot;.
- &quot;Debug&quot; produces very useful information for finding problems. There is usually no noteworthy performance impact but the file may become rather large. If this is a problem you may prefer the &quot;Info&quot; level for regular use. On the &quot;Error&quot; level the log file usually remains empty.
+ Maximum number of crash dumps to keep on disk. Use 0 for unlimited.
+ Set &quot;Crash Dumps&quot; above to None to disable crash dump collection.
</string>
</property>
</widget>
</item>
+ <item row="3" column="0">
+ <widget class="QLabel" name="label_32">
+ <property name="text">
+ <string>LOOT Log Level</string>
+ </property>
+ </widget>
+ </item>
+ <item row="3" column="1">
+ <widget class="QComboBox" name="lootLogLevel"/>
+ </item>
</layout>
</item>
</layout>
@@ -1589,9 +1584,6 @@ programs you are intentionally running.</string>
<tabstop>bsaDateBtn</tabstop>
<tabstop>execBlacklistBtn</tabstop>
<tabstop>resetGeometryBtn</tabstop>
- <tabstop>logLevelBox</tabstop>
- <tabstop>dumpsTypeBox</tabstop>
- <tabstop>dumpsMaxEdit</tabstop>
</tabstops>
<resources>
<include location="resources.qrc"/>
diff --git a/src/settingsdialogdiagnostics.cpp b/src/settingsdialogdiagnostics.cpp
index 386c7425..74cadaa9 100644
--- a/src/settingsdialogdiagnostics.cpp
+++ b/src/settingsdialogdiagnostics.cpp
@@ -9,7 +9,8 @@ using namespace MOBase;
DiagnosticsSettingsTab::DiagnosticsSettingsTab(Settings& s, SettingsDialog& d)
: SettingsTab(s, d)
{
- setLevelsBox();
+ setLogLevel();
+ setLootLogLevel();
setCrashDumpTypesBox();
ui->dumpsMaxEdit->setValue(settings().diagnostics().crashDumpsMax());
@@ -26,7 +27,7 @@ DiagnosticsSettingsTab::DiagnosticsSettingsTab(Settings& s, SettingsDialog& d)
);
}
-void DiagnosticsSettingsTab::setLevelsBox()
+void DiagnosticsSettingsTab::setLogLevel()
{
ui->logLevelBox->clear();
@@ -35,14 +36,40 @@ void DiagnosticsSettingsTab::setLevelsBox()
ui->logLevelBox->addItem(QObject::tr("Warning"), log::Warning);
ui->logLevelBox->addItem(QObject::tr("Error"), log::Error);
+ const auto sel = settings().diagnostics().logLevel();
+
for (int i=0; i<ui->logLevelBox->count(); ++i) {
- if (ui->logLevelBox->itemData(i) == settings().diagnostics().logLevel()) {
+ if (ui->logLevelBox->itemData(i) == sel) {
ui->logLevelBox->setCurrentIndex(i);
break;
}
}
}
+void DiagnosticsSettingsTab::setLootLogLevel()
+{
+ using L = lootcli::LogLevels;
+
+ auto v = [](L level) { return QVariant(static_cast<int>(level)); };
+
+ ui->lootLogLevel->clear();
+
+ ui->lootLogLevel->addItem(QObject::tr("Trace"), v(L::Trace));
+ ui->lootLogLevel->addItem(QObject::tr("Debug"), v(L::Debug));
+ ui->lootLogLevel->addItem(QObject::tr("Info (recommended)"), v(L::Info));
+ ui->lootLogLevel->addItem(QObject::tr("Warning"), v(L::Warning));
+ ui->lootLogLevel->addItem(QObject::tr("Error"), v(L::Error));
+
+ const auto sel = settings().diagnostics().lootLogLevel();
+
+ for (int i=0; i<ui->lootLogLevel->count(); ++i) {
+ if (ui->lootLogLevel->itemData(i) == v(sel)) {
+ ui->lootLogLevel->setCurrentIndex(i);
+ break;
+ }
+ }
+}
+
void DiagnosticsSettingsTab::setCrashDumpTypesBox()
{
ui->dumpsTypeBox->clear();
@@ -76,4 +103,7 @@ void DiagnosticsSettingsTab::update()
static_cast<CrashDumpsType>(ui->dumpsTypeBox->currentData().toInt()));
settings().diagnostics().setCrashDumpsMax(ui->dumpsMaxEdit->value());
+
+ settings().diagnostics().setLootLogLevel(
+ static_cast<lootcli::LogLevels>(ui->lootLogLevel->currentData().toInt()));
}
diff --git a/src/settingsdialogdiagnostics.h b/src/settingsdialogdiagnostics.h
index f0fbf770..e01ee22f 100644
--- a/src/settingsdialogdiagnostics.h
+++ b/src/settingsdialogdiagnostics.h
@@ -12,7 +12,8 @@ public:
void update();
private:
- void setLevelsBox();
+ void setLogLevel();
+ void setLootLogLevel();
void setCrashDumpTypesBox();
};