From 46d186a49f1d1e6e30c04f9461ca72beadf80182 Mon Sep 17 00:00:00 2001 From: Dave Page Date: Thu, 7 May 2020 11:01:02 +0100 Subject: [PATCH] Show the startup log as well as the server log in the runtime's log viewer. Fixes #5489 --- docs/en_US/release_notes_4_22.rst | 1 + runtime/LogWindow.cpp | 36 +++++++++++++++++++++---------- runtime/LogWindow.h | 10 ++++++--- runtime/LogWindow.ui | 34 ++++++++++++++++++++++++++++- runtime/MenuActions.cpp | 2 +- 5 files changed, 67 insertions(+), 16 deletions(-) diff --git a/docs/en_US/release_notes_4_22.rst b/docs/en_US/release_notes_4_22.rst index ec58ea765..b846211e9 100644 --- a/docs/en_US/release_notes_4_22.rst +++ b/docs/en_US/release_notes_4_22.rst @@ -9,6 +9,7 @@ This release contains a number of bug fixes and new features since the release o New features ************ +| `Issue #5489 `_ - Show the startup log as well as the server log in the runtime's log viewer. Housekeeping ************ diff --git a/runtime/LogWindow.cpp b/runtime/LogWindow.cpp index 4d9d6962e..748468004 100644 --- a/runtime/LogWindow.cpp +++ b/runtime/LogWindow.cpp @@ -9,6 +9,7 @@ // ////////////////////////////////////////////////////////////////////////// +#include "pgAdmin4.h" #include "LogWindow.h" #include "ui_LogWindow.h" @@ -16,10 +17,10 @@ #include -LogWindow::LogWindow(QWidget *parent, QString logFile) : +LogWindow::LogWindow(QWidget *parent, QString serverLogFile) : QDialog(parent), ui(new Ui::LogWindow), - m_logFile(logFile) + m_serverLogFile(serverLogFile) { ui->setupUi(this); } @@ -31,14 +32,27 @@ LogWindow::~LogWindow() } +void LogWindow::LoadLog() +{ + int startupLines, serverLines; + + ui->lblStatus->setText(tr("Loading logfiles...")); + + startupLines = this->readLog(QDir::homePath() + (QString("/.%1.startup.log").arg(PGA_APP_NAME)).remove(" "), ui->textStartupLog); + serverLines = this->readLog(m_serverLogFile, ui->textServerLog); + + ui->lblStatus->setText(QString(tr("Loaded startup log (%1 lines) and server log (%2 lines).")).arg(startupLines).arg(serverLines)); +} + + void LogWindow::reload() { - this->ReadLog(); + this->LoadLog(); } // Read the logfile -void LogWindow::ReadLog() +int LogWindow::readLog(QString logFile, QPlainTextEdit *logWidget) { FILE *log; char *buffer; @@ -47,20 +61,19 @@ void LogWindow::ReadLog() // Look busy! QApplication::setOverrideCursor(Qt::WaitCursor); - ui->lblStatus->setText(tr("Loading logfile...")); this->setDisabled(true); QCoreApplication::processEvents( QEventLoop::AllEvents, 100 ); - ui->textLog->clear(); + logWidget->clear(); // Attempt to open the file - log = fopen(m_logFile.toUtf8().data(), "r"); + log = fopen(logFile.toUtf8().data(), "r"); if (log == Q_NULLPTR) { - ui->textLog->setPlainText(QString(tr("The log file (%1) could not be opened.")).arg(m_logFile)); + logWidget->setPlainText(QString(tr("The log file (%1) could not be opened.")).arg(m_serverLogFile)); this->setDisabled(false); QApplication::restoreOverrideCursor(); - return; + return 0; } // Get the file size, and read the data @@ -80,10 +93,11 @@ void LogWindow::ReadLog() buffer[i] = 0; fclose(log); - ui->textLog->setPlainText(buffer); + logWidget->setPlainText(buffer); // And... relax - ui->lblStatus->setText(QString(tr("Loaded logfile (%1 lines).")).arg(lines)); this->setDisabled(false); QApplication::restoreOverrideCursor(); + + return lines; } diff --git a/runtime/LogWindow.h b/runtime/LogWindow.h index 5f7bc8633..2ff1c2ebf 100644 --- a/runtime/LogWindow.h +++ b/runtime/LogWindow.h @@ -13,6 +13,7 @@ #define LOGWINDOW_H #include +#include namespace Ui { class LogWindow; @@ -23,10 +24,10 @@ class LogWindow : public QDialog Q_OBJECT public: - explicit LogWindow(QWidget *parent = Q_NULLPTR, QString logFile = ""); + explicit LogWindow(QWidget *parent = Q_NULLPTR, QString serverLogFile = ""); ~LogWindow(); - void ReadLog(); + void LoadLog(); private slots: void reload(); @@ -34,7 +35,10 @@ private slots: private: Ui::LogWindow *ui; - QString m_logFile; + QString m_startupLogFile; + QString m_serverLogFile; + + int readLog(QString logFile, QPlainTextEdit *logWidget); }; #endif // LOGWINDOW_H diff --git a/runtime/LogWindow.ui b/runtime/LogWindow.ui index e5ae71e78..48ba616b0 100644 --- a/runtime/LogWindow.ui +++ b/runtime/LogWindow.ui @@ -15,7 +15,39 @@ - + + + Startup Log: + + + + + + + + Courier + + + + true + + + + + + false + + + + + + + Server Log: + + + + + Courier diff --git a/runtime/MenuActions.cpp b/runtime/MenuActions.cpp index 18d578922..e4013855e 100644 --- a/runtime/MenuActions.cpp +++ b/runtime/MenuActions.cpp @@ -134,7 +134,7 @@ void MenuActions::onLog() QCoreApplication::processEvents( QEventLoop::AllEvents, 100 ); - m_logWindow->ReadLog(); + m_logWindow->LoadLog(); }