@@ -328,16 +328,16 @@ void RPCConsole::errorLogInitPos()
328
328
if (errorLogFile == NULL ) {
329
329
// Get a QFile instance
330
330
errorLogFile = new QFile (QString::fromStdString (GetErrorLogPath ().string ()));
331
- }
332
331
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 ;
337
336
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
+ }
341
341
342
342
// Seek to the end of file
343
343
errorLogFile->seek (errorLogFile->size () - 1 );
@@ -358,11 +358,16 @@ void RPCConsole::errorLogInitPos()
358
358
lineCount++; // Count it
359
359
}
360
360
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
+ }
363
368
364
369
// Clear the textarea
365
- ui->errorLogTextBrowser ->setText ( " " );
370
+ ui->errorLogTextBrowser ->clear ( );
366
371
367
372
// Mark init as done
368
373
errorLogInitPosDone = true ;
@@ -377,6 +382,13 @@ void RPCConsole::errorLogRefresh()
377
382
// Set to refreshing
378
383
errorLogRefreshing = true ;
379
384
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
+
380
392
// Check if we have initialized debug log already
381
393
if (!errorLogInitPosDone)
382
394
errorLogInitPos ();
@@ -390,46 +402,9 @@ void RPCConsole::errorLogRefresh()
390
402
QTextStream in (errorLogFile);
391
403
392
404
// Load up the lines
393
- QString logLines = " " ;
394
405
while (!in.atEnd ()) {
395
406
// 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 ());
433
408
}
434
409
435
410
// Mark as done
0 commit comments