Browse Source

Add tab for viewing the debug log

This adds a tab where the user can easily see the last X lines of the debug.log file.

Currently it shows the last 100 lines as of the time that SD starts up. Next will be
to have a way to show updated data (such as a refresh button) and allow customizing
the number of lines to show.
pull/148/head
Duke 4 months ago
parent
commit
0f45b3fe5b
  1. 69
      src/mainwindow.cpp
  2. 1
      src/mainwindow.h
  3. 19
      src/mainwindow.ui

69
src/mainwindow.cpp

@ -136,6 +136,7 @@ MainWindow::MainWindow(QWidget *parent) :
qDebug() << "Created RPC";
setupMiningTab();
setupDebugLogTab();
restoreSavedStates();
}
@ -1984,6 +1985,49 @@ void MainWindow::setupMiningTab() {
// Mining tab currently only enabled for DragonX
}
}
void MainWindow::setupDebugLogTab() {
ui->debugLog->setReadOnly(true);
ui->debugLog->setPlainText("Some debug stuff");
#ifdef Q_OS_LINUX
QFile file(QDir::homePath() + "/.hush/HUSH3/debug.log");
#elif defined(Q_OS_DARWIN)
QFile file(QDir::homePath() + "/Library/Application Support/Hush/HUSH3/debug.log");
#elif defined(Q_OS_WIN64)
QFile file(QDir::homePath() + "/AppData/Roaming/Hush/HUSH3/debug.log");
#else
// Bless Your Heart, You Like Danger!
QFile file("~/.hush/HUSH3/debug.log");
#endif // Q_OS_LINUX
if(file.exists()) {
DEBUG(": Found debug.log at " << file);
} else {
DEBUG("No debug.log found!");
return;
}
if(file.open(QIODevice::ReadOnly))
{
qint64 fileSize = file.size();
DEBUG("debug.log size=" << fileSize);
file.seek(file.size()-1);
int count = 0;
int lines = 100;
while ( (count < lines) && (file.pos() > 0) )
{
QString ch = file.read(1);
file.seek(file.pos()-2);
if (ch == "\n")
count++;
}
file.seek(file.pos()+2);
QString debugText = file.readAll();
ui->debugLog->setPlainText( debugText );
}
}
void MainWindow::setupPeersTab() {
qDebug() << __FUNCTION__;
// Set up context menu on peers tab
@ -2134,33 +2178,8 @@ void MainWindow::setupPeersTab() {
menu.exec(ui->peersTable->viewport()->mapToGlobal(pos));
});
/*
//grep 'BAN THRESHOLD EXCEEDED' ~/.hush/HUSH3/debug.log
//grep Disconnected ...
QFile debuglog = "";
#ifdef Q_OS_LINUX
debuglog = "~/.hush/HUSH3/debug.log";
#elif defined(Q_OS_DARWIN)
debuglog = "~/Library/Application Support/Hush/HUSH3/debug.log";
#elif defined(Q_OS_WIN64)
// "C:/Users/<USER>/AppData/Roaming/<APPNAME>",
// TODO: get current username
debuglog = "C:/Users/<USER>/AppData/Roaming/Hush/HUSH3/debug.log";
#else
// Bless Your Heart, You Like Danger!
// There are open bounties to port HUSH softtware to OpenBSD and friends:
// git.hush.is/hush/tasks
debuglog = "~/.hush/HUSH3/debug.log";
#endif // Q_OS_LINUX
if(debuglog.exists()) {
qDebug() << __func__ << ": Found debuglog at " << debuglog;
} else {
qDebug() << __func__ << ": No debug.log found";
}
*/
//ui->recentlyBannedPeers = "Could not open " + debuglog;
}

1
src/mainwindow.h

@ -94,6 +94,7 @@ private:
void setupChatTab();
void setupMarketTab();
void setupMiningTab();
void setupDebugLogTab();
void slot_change_theme(QString& themeName);
void slot_change_currency(const QString& currencyName);

19
src/mainwindow.ui

@ -1130,6 +1130,24 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_debug">
<attribute name="title">
<string>Debug Log</string>
</attribute>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="3">
<widget class="QPlainTextEdit" name="debugLog">
<property name="plainText">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="tab_5">
<attribute name="title">
<string>Node info</string>
@ -1602,6 +1620,7 @@
</item>
</layout>
</widget>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>

Loading…
Cancel
Save