From 0f45b3fe5b636c303066f797c19a756e1777e7e7 Mon Sep 17 00:00:00 2001 From: Duke Date: Fri, 29 Dec 2023 21:24:50 -0500 Subject: [PATCH 1/3] 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 @@ + From da3fb9c8a422a0843229ac228ae3083ee2135ea4 Mon Sep 17 00:00:00 2001 From: Duke Date: Sat, 30 Dec 2023 05:40:25 -0500 Subject: [PATCH 2/3] Add refresh button for debug log --- src/mainwindow.cpp | 23 +++++++++++++++++------ src/mainwindow.h | 1 + src/mainwindow.ui | 29 ++++++++++++++++++++++++++++- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 9fe09d4..d0ee83b 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1986,10 +1986,7 @@ void MainWindow::setupMiningTab() { } } -void MainWindow::setupDebugLogTab() { - ui->debugLog->setReadOnly(true); - ui->debugLog->setPlainText("Some debug stuff"); - +QString MainWindow::readDebugLines() { #ifdef Q_OS_LINUX QFile file(QDir::homePath() + "/.hush/HUSH3/debug.log"); #elif defined(Q_OS_DARWIN) @@ -2004,7 +2001,7 @@ void MainWindow::setupDebugLogTab() { DEBUG(": Found debug.log at " << file); } else { DEBUG("No debug.log found!"); - return; + return ""; } if(file.open(QIODevice::ReadOnly)) @@ -2023,9 +2020,23 @@ void MainWindow::setupDebugLogTab() { } file.seek(file.pos()+2); QString debugText = file.readAll(); - ui->debugLog->setPlainText( debugText ); + DEBUG("got " << debugText.size() << " bytes of debugText"); + file.close(); + return debugText; } + return ""; +} + +void MainWindow::setupDebugLogTab() { + ui->debugLog->setReadOnly(true); + ui->debugLog->setPlainText("Loading debug log..."); + + QObject::connect(ui->refreshDebugButton, &QPushButton::clicked, [=] () { + DEBUG("refresh debug log clicked"); + ui->debugLog->setPlainText( readDebugLines() ); + }); + ui->debugLog->setPlainText( readDebugLines() ); } void MainWindow::setupPeersTab() { diff --git a/src/mainwindow.h b/src/mainwindow.h index e5c9024..1f0ea51 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -85,6 +85,7 @@ private: void closeEvent(QCloseEvent* event); + QString readDebugLines(); void setupSendTab(); void setupPeersTab(); void setupTransactionsTab(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index 69e5c82..bdbbfdf 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1137,7 +1137,34 @@ - + + + + + true + + + + 0 + 0 + + + + + 0 + 0 + + + + Click to see the latest debug log data + + + + Refresh + + + + From 702619a8e01e5adebcc5cf0508cc485c3066c9db Mon Sep 17 00:00:00 2001 From: Duke Date: Sat, 30 Dec 2023 08:50:10 -0500 Subject: [PATCH 3/3] Support dragonx debug log and custom number of lines --- src/mainwindow.cpp | 24 +++++++++++++++--------- src/mainwindow.h | 2 +- src/mainwindow.ui | 19 ++++++++++++++++++- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index d0ee83b..f9e8afb 100755 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -1986,16 +1986,17 @@ void MainWindow::setupMiningTab() { } } -QString MainWindow::readDebugLines() { +QString MainWindow::readDebugLines(uint32_t lines) { + QString coin = isdragonx ? "DRAGONX" : "HUSH3"; #ifdef Q_OS_LINUX - QFile file(QDir::homePath() + "/.hush/HUSH3/debug.log"); + QFile file(QDir::homePath() + "/.hush/" + coin + "/debug.log"); #elif defined(Q_OS_DARWIN) - QFile file(QDir::homePath() + "/Library/Application Support/Hush/HUSH3/debug.log"); + QFile file(QDir::homePath() + "/Library/Application Support/Hush/" + coin + "/debug.log"); #elif defined(Q_OS_WIN64) - QFile file(QDir::homePath() + "/AppData/Roaming/Hush/HUSH3/debug.log"); + QFile file(QDir::homePath() + "/AppData/Roaming/Hush/" + coin + "/debug.log"); #else // Bless Your Heart, You Like Danger! - QFile file("~/.hush/HUSH3/debug.log"); + QFile file(QDir::homePath() + "/.hush/" + coin + "/debug.log"); #endif // Q_OS_LINUX if(file.exists()) { DEBUG(": Found debug.log at " << file); @@ -2008,9 +2009,12 @@ QString MainWindow::readDebugLines() { { qint64 fileSize = file.size(); DEBUG("debug.log size=" << fileSize); + if(fileSize < 2) { + DEBUG("debug.log is too small"); + return ""; + } file.seek(file.size()-1); - int count = 0; - int lines = 100; + uint32_t count = 0; while ( (count < lines) && (file.pos() > 0) ) { QString ch = file.read(1); @@ -2032,8 +2036,10 @@ void MainWindow::setupDebugLogTab() { ui->debugLog->setPlainText("Loading debug log..."); QObject::connect(ui->refreshDebugButton, &QPushButton::clicked, [=] () { - DEBUG("refresh debug log clicked"); - ui->debugLog->setPlainText( readDebugLines() ); + uint32_t debugLines = ui->debugLines->text().trimmed().toInt(); + if (debugLines == 0) { debugLines = 50; } + DEBUG("refresh debug log clicked with debugLines=" << debugLines); + ui->debugLog->setPlainText( readDebugLines(debugLines) ); }); ui->debugLog->setPlainText( readDebugLines() ); diff --git a/src/mainwindow.h b/src/mainwindow.h index 1f0ea51..f4eaf05 100644 --- a/src/mainwindow.h +++ b/src/mainwindow.h @@ -85,7 +85,7 @@ private: void closeEvent(QCloseEvent* event); - QString readDebugLines(); + QString readDebugLines(uint32_t lines = 50); void setupSendTab(); void setupPeersTab(); void setupTransactionsTab(); diff --git a/src/mainwindow.ui b/src/mainwindow.ui index bdbbfdf..899abc5 100644 --- a/src/mainwindow.ui +++ b/src/mainwindow.ui @@ -1164,7 +1164,24 @@ - + + + + Number of lines to show + + + + + + + true + + + 50 + + + +