Show the startup log as well as the server log in the runtime's log viewer. Fixes #5489

This commit is contained in:
Dave Page 2020-05-07 11:01:02 +01:00
parent 7164c677de
commit 46d186a49f
5 changed files with 67 additions and 16 deletions

View File

@ -9,6 +9,7 @@ This release contains a number of bug fixes and new features since the release o
New features
************
| `Issue #5489 <https://redmine.postgresql.org/issues/5489>`_ - Show the startup log as well as the server log in the runtime's log viewer.
Housekeeping
************

View File

@ -9,6 +9,7 @@
//
//////////////////////////////////////////////////////////////////////////
#include "pgAdmin4.h"
#include "LogWindow.h"
#include "ui_LogWindow.h"
@ -16,10 +17,10 @@
#include <stdio.h>
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;
}

View File

@ -13,6 +13,7 @@
#define LOGWINDOW_H
#include <QDialog>
#include <QPlainTextEdit>
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

View File

@ -15,7 +15,39 @@
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPlainTextEdit" name="textLog">
<widget class="QLabel" name="lblStartupLog">
<property name="text">
<string>Startup Log:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="textStartupLog">
<property name="font">
<font>
<family>Courier</family>
</font>
</property>
<property name="readOnly">
<bool>true</bool>
</property>
<property name="plainText">
<string notr="true"/>
</property>
<property name="centerOnScroll">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="lblServerLog">
<property name="text">
<string>Server Log:</string>
</property>
</widget>
</item>
<item>
<widget class="QPlainTextEdit" name="textServerLog">
<property name="font">
<font>
<family>Courier</family>

View File

@ -134,7 +134,7 @@ void MenuActions::onLog()
QCoreApplication::processEvents( QEventLoop::AllEvents, 100 );
m_logWindow->ReadLog();
m_logWindow->LoadLog();
}