Skip to content

Commit

Permalink
Merge pull request #532 from mxaddict/patch-30
Browse files Browse the repository at this point in the history
Updated the error log tab logic
  • Loading branch information
proletesseract committed Jun 29, 2019
2 parents a16c48f + c082708 commit a4f23ac
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 50 deletions.
73 changes: 24 additions & 49 deletions src/qt/rpcconsole.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -328,16 +328,16 @@ void RPCConsole::errorLogInitPos()
if (errorLogFile == NULL) {
// Get a QFile instance
errorLogFile = new QFile(QString::fromStdString(GetErrorLogPath().string()));
}

// Check if we have a log file
// We can't tail a missing file
if (!errorLogFile->exists())
return;
// Check if we have a log file
// We can't tail a missing file
if (!errorLogFile->exists())
return;

// Try to open file
if (!errorLogFile->open(QFile::ReadOnly | QFile::Text))
return;
// Try to open file
if (!errorLogFile->open(QFile::ReadOnly | QFile::Text))
return;
}

// Seek to the end of file
errorLogFile->seek(errorLogFile->size() - 1);
Expand All @@ -358,11 +358,16 @@ void RPCConsole::errorLogInitPos()
lineCount++; // Count it
}

// Move pos forward by 2 spaces
errorLogFile->seek(errorLogFile->pos() + 2);
// Check if we are not at the start of the file
if (errorLogFile->pos() > 0)
{
// Move pos forward by 2 spaces
// This is so that we don't show the last lines last 2 chars
errorLogFile->seek(errorLogFile->pos() + 2);
}

// Clear the textarea
ui->errorLogTextBrowser->setText("");
ui->errorLogTextBrowser->clear();

// Mark init as done
errorLogInitPosDone = true;
Expand All @@ -377,6 +382,13 @@ void RPCConsole::errorLogRefresh()
// Set to refreshing
errorLogRefreshing = true;

// Count the lines in the UI textarea
int uiLineCount = ui->errorLogTextBrowser->document()->lineCount();

// Check if lineCount is 2*ERROR_LOG_INITIAL_COUNT
if (uiLineCount >= ERROR_LOG_INITIAL_COUNT * 2)
errorLogInitPosDone = false;

// Check if we have initialized debug log already
if (!errorLogInitPosDone)
errorLogInitPos();
Expand All @@ -390,46 +402,9 @@ void RPCConsole::errorLogRefresh()
QTextStream in(errorLogFile);

// Load up the lines
QString logLines = "";
while (!in.atEnd()) {
// Load the next line
logLines += in.readLine() + "\n";
}

// Check if we have lines
if (logLines != "") {
// Add the new lines, purpose of duplicate moveCursor calls is
// to auto scroll to the end of the log instead of sticking to the
// top of the text area
ui->errorLogTextBrowser->moveCursor(QTextCursor::End);
ui->errorLogTextBrowser->textCursor().insertText(logLines);
ui->errorLogTextBrowser->moveCursor(QTextCursor::End);
}

// Count the lines in the UI textarea
int uiLineCount = ui->errorLogTextBrowser->document()->lineCount();

// Check if lines are more than ERROR_LOG_INITIAL_COUNT
if (uiLineCount > ERROR_LOG_INITIAL_COUNT) {
// Count how many to remove
int lineCountDiff = uiLineCount - ERROR_LOG_INITIAL_COUNT;

// Get our cursor
QTextCursor cursor = ui->errorLogTextBrowser->textCursor();

// REMOVE THEM
for (int i = 0; i < lineCountDiff; i++) {
cursor.movePosition(QTextCursor::Start);
cursor.select(QTextCursor::LineUnderCursor);
cursor.deleteChar(); // Remove the selected text
cursor.deleteChar(); // This is by design, this removes the \n
}

// Replace the cursor
ui->errorLogTextBrowser->setTextCursor(cursor);

// Move cursor back to the end
ui->errorLogTextBrowser->moveCursor(QTextCursor::End);
ui->errorLogTextBrowser->append(in.readLine());
}

// Mark as done
Expand Down
3 changes: 2 additions & 1 deletion src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,8 @@ static int DebugLogWriteStr(const std::string &str)
static int ErrorLogWriteStr(const std::string &str)
{
// Return the int from the write size
return FileWriteStr(str, fileoutErrorLog); // write to error log
return FileWriteStr(str, fileoutDebugLog) + // write to debug log
FileWriteStr(str, fileoutErrorLog); // write to error log
}

static void DebugPrintInit()
Expand Down

0 comments on commit a4f23ac

Please sign in to comment.