@@ -328,16 +328,16 @@ void RPCConsole::errorLogInitPos()
328328 if (errorLogFile == NULL ) {
329329 // Get a QFile instance
330330 errorLogFile = new QFile (QString::fromStdString (GetErrorLogPath ().string ()));
331- }
332331
333- // Check if we have a log file
334- // We can't tail a missing file
335- if (!errorLogFile->exists ())
336- return ;
332+ // Check if we have a log file
333+ // We can't tail a missing file
334+ if (!errorLogFile->exists ())
335+ return ;
337336
338- // Try to open file
339- if (!errorLogFile->open (QFile::ReadOnly | QFile::Text))
340- return ;
337+ // Try to open file
338+ if (!errorLogFile->open (QFile::ReadOnly | QFile::Text))
339+ return ;
340+ }
341341
342342 // Seek to the end of file
343343 errorLogFile->seek (errorLogFile->size () - 1 );
@@ -358,11 +358,16 @@ void RPCConsole::errorLogInitPos()
358358 lineCount++; // Count it
359359 }
360360
361- // Move pos forward by 2 spaces
362- errorLogFile->seek (errorLogFile->pos () + 2 );
361+ // Check if we are not at the start of the file
362+ if (errorLogFile->pos () > 0 )
363+ {
364+ // Move pos forward by 2 spaces
365+ // This is so that we don't show the last lines last 2 chars
366+ errorLogFile->seek (errorLogFile->pos () + 2 );
367+ }
363368
364369 // Clear the textarea
365- ui->errorLogTextBrowser ->setText ( " " );
370+ ui->errorLogTextBrowser ->clear ( );
366371
367372 // Mark init as done
368373 errorLogInitPosDone = true ;
@@ -377,6 +382,13 @@ void RPCConsole::errorLogRefresh()
377382 // Set to refreshing
378383 errorLogRefreshing = true ;
379384
385+ // Count the lines in the UI textarea
386+ int uiLineCount = ui->errorLogTextBrowser ->document ()->lineCount ();
387+
388+ // Check if lineCount is 2*ERROR_LOG_INITIAL_COUNT
389+ if (uiLineCount >= ERROR_LOG_INITIAL_COUNT * 2 )
390+ errorLogInitPosDone = false ;
391+
380392 // Check if we have initialized debug log already
381393 if (!errorLogInitPosDone)
382394 errorLogInitPos ();
@@ -390,46 +402,9 @@ void RPCConsole::errorLogRefresh()
390402 QTextStream in (errorLogFile);
391403
392404 // Load up the lines
393- QString logLines = " " ;
394405 while (!in.atEnd ()) {
395406 // Load the next line
396- logLines += in.readLine () + " \n " ;
397- }
398-
399- // Check if we have lines
400- if (logLines != " " ) {
401- // Add the new lines, purpose of duplicate moveCursor calls is
402- // to auto scroll to the end of the log instead of sticking to the
403- // top of the text area
404- ui->errorLogTextBrowser ->moveCursor (QTextCursor::End);
405- ui->errorLogTextBrowser ->textCursor ().insertText (logLines);
406- ui->errorLogTextBrowser ->moveCursor (QTextCursor::End);
407- }
408-
409- // Count the lines in the UI textarea
410- int uiLineCount = ui->errorLogTextBrowser ->document ()->lineCount ();
411-
412- // Check if lines are more than ERROR_LOG_INITIAL_COUNT
413- if (uiLineCount > ERROR_LOG_INITIAL_COUNT) {
414- // Count how many to remove
415- int lineCountDiff = uiLineCount - ERROR_LOG_INITIAL_COUNT;
416-
417- // Get our cursor
418- QTextCursor cursor = ui->errorLogTextBrowser ->textCursor ();
419-
420- // REMOVE THEM
421- for (int i = 0 ; i < lineCountDiff; i++) {
422- cursor.movePosition (QTextCursor::Start);
423- cursor.select (QTextCursor::LineUnderCursor);
424- cursor.deleteChar (); // Remove the selected text
425- cursor.deleteChar (); // This is by design, this removes the \n
426- }
427-
428- // Replace the cursor
429- ui->errorLogTextBrowser ->setTextCursor (cursor);
430-
431- // Move cursor back to the end
432- ui->errorLogTextBrowser ->moveCursor (QTextCursor::End);
407+ ui->errorLogTextBrowser ->append (in.readLine ());
433408 }
434409
435410 // Mark as done
0 commit comments