From 0f45b3fe5b636c303066f797c19a756e1777e7e7 Mon Sep 17 00:00:00 2001 From: Duke Date: Fri, 29 Dec 2023 21:24:50 -0500 Subject: [PATCH] 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. --- src/mainwindow.cpp | 69 +++++++++++++++++++++++++++++----------------- src/mainwindow.h | 1 + src/mainwindow.ui | 19 +++++++++++++ 3 files changed, 64 insertions(+), 25 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 1e69e33..9fe09d4 100755 --- a/src/mainwindow.cpp +++ b/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//AppData/Roaming/", - // TODO: get current username - debuglog = "C:/Users//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; } diff --git a/src/mainwindow.h b/src/mainwindow.h index 53e60cc..e5c9024 100644 --- a/src/mainwindow.h +++ b/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); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index e7e3734..69e5c82 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1130,6 +1130,24 @@ + + + + Debug Log + + + + + + + + + + + + + + Node info @@ -1602,6 +1620,7 @@ +