2018-02-05 09:32:14 -06:00
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// pgAdmin 4 - PostgreSQL Tools
|
|
|
|
//
|
2020-01-02 08:43:50 -06:00
|
|
|
// Copyright (C) 2013 - 2020, The pgAdmin Development Team
|
2018-02-05 09:32:14 -06:00
|
|
|
// This software is released under the PostgreSQL Licence
|
|
|
|
//
|
|
|
|
// LogWindow.cpp - Log viewer window
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "LogWindow.h"
|
|
|
|
#include "ui_LogWindow.h"
|
|
|
|
|
|
|
|
#include <QTime>
|
|
|
|
|
2018-03-21 09:49:39 -05:00
|
|
|
#include <stdio.h>
|
2018-02-05 09:32:14 -06:00
|
|
|
|
|
|
|
LogWindow::LogWindow(QWidget *parent, QString logFile) :
|
|
|
|
QDialog(parent),
|
|
|
|
ui(new Ui::LogWindow),
|
|
|
|
m_logFile(logFile)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
LogWindow::~LogWindow()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void LogWindow::reload()
|
|
|
|
{
|
|
|
|
this->ReadLog();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Read the logfile
|
|
|
|
void LogWindow::ReadLog()
|
|
|
|
{
|
|
|
|
FILE *log;
|
|
|
|
char *buffer;
|
|
|
|
long len = 0;
|
|
|
|
int i, lines = 0;
|
|
|
|
|
|
|
|
// Look busy!
|
|
|
|
QApplication::setOverrideCursor(Qt::WaitCursor);
|
|
|
|
ui->lblStatus->setText(tr("Loading logfile..."));
|
|
|
|
this->setDisabled(true);
|
|
|
|
QCoreApplication::processEvents( QEventLoop::AllEvents, 100 );
|
|
|
|
|
|
|
|
ui->textLog->clear();
|
|
|
|
|
|
|
|
// Attempt to open the file
|
|
|
|
log = fopen(m_logFile.toUtf8().data(), "r");
|
2018-12-06 04:40:49 -06:00
|
|
|
if (log == Q_NULLPTR)
|
2018-02-05 09:32:14 -06:00
|
|
|
{
|
|
|
|
ui->textLog->setPlainText(QString(tr("The log file (%1) could not be opened.")).arg(m_logFile));
|
|
|
|
this->setDisabled(false);
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the file size, and read the data
|
|
|
|
fseek(log, 0, SEEK_END);
|
|
|
|
len = ftell(log);
|
|
|
|
rewind(log);
|
2018-12-06 04:36:57 -06:00
|
|
|
buffer = static_cast<char *>(malloc((len + 1) * sizeof(char)));
|
2018-02-05 09:32:14 -06:00
|
|
|
|
|
|
|
for (i = 0; i < len; i++) {
|
|
|
|
if (fread(buffer + i, 1, 1, log) > 0)
|
|
|
|
{
|
|
|
|
if (buffer[i] == '\n')
|
|
|
|
lines++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer[i] = 0;
|
|
|
|
|
|
|
|
fclose(log);
|
|
|
|
ui->textLog->setPlainText(buffer);
|
|
|
|
|
|
|
|
// And... relax
|
|
|
|
ui->lblStatus->setText(QString(tr("Loaded logfile (%1 lines).")).arg(lines));
|
|
|
|
this->setDisabled(false);
|
|
|
|
QApplication::restoreOverrideCursor();
|
|
|
|
}
|