Improved logging code. Each log line now has a timestamp.
This commit is contained in:
parent
36f35075ed
commit
b160867111
@ -295,7 +295,7 @@ QModelIndex JobListModel::insertJob(EncodeThread *thread)
|
|||||||
|
|
||||||
connect(thread, SIGNAL(statusChanged(QUuid, JobStatus)), this, SLOT(updateStatus(QUuid, JobStatus)), Qt::QueuedConnection);
|
connect(thread, SIGNAL(statusChanged(QUuid, JobStatus)), this, SLOT(updateStatus(QUuid, JobStatus)), Qt::QueuedConnection);
|
||||||
connect(thread, SIGNAL(progressChanged(QUuid, unsigned int)), this, SLOT(updateProgress(QUuid, unsigned int)), Qt::QueuedConnection);
|
connect(thread, SIGNAL(progressChanged(QUuid, unsigned int)), this, SLOT(updateProgress(QUuid, unsigned int)), Qt::QueuedConnection);
|
||||||
connect(thread, SIGNAL(messageLogged(QUuid, QString)), logFile, SLOT(addLogMessage(QUuid, QString)), Qt::QueuedConnection);
|
connect(thread, SIGNAL(messageLogged(QUuid, qint64, QString)), logFile, SLOT(addLogMessage(QUuid, qint64, QString)), Qt::QueuedConnection);
|
||||||
connect(thread, SIGNAL(detailsChanged(QUuid, QString)), this, SLOT(updateDetails(QUuid, QString)), Qt::QueuedConnection);
|
connect(thread, SIGNAL(detailsChanged(QUuid, QString)), this, SLOT(updateDetails(QUuid, QString)), Qt::QueuedConnection);
|
||||||
|
|
||||||
return createIndex(m_jobs.count() - 1, 0, NULL);
|
return createIndex(m_jobs.count() - 1, 0, NULL);
|
||||||
|
@ -27,13 +27,18 @@
|
|||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
|
#include <QDateTime>
|
||||||
|
|
||||||
|
static const QLatin1String FMT_TIMESTAMP("[yyyy-MM-dd][HH:mm:ss] ");
|
||||||
|
|
||||||
LogFileModel::LogFileModel(const QString &sourceName, const QString &outputName, const QString &configName)
|
LogFileModel::LogFileModel(const QString &sourceName, const QString &outputName, const QString &configName)
|
||||||
{
|
{
|
||||||
m_lines << "Job not started yet." << QString();
|
const qint64 timeStamp = QDateTime::currentMSecsSinceEpoch();
|
||||||
m_lines << QString("Scheduled source: %1").arg(QDir::toNativeSeparators(sourceName));
|
m_lines << qMakePair(timeStamp, QString("Job not started yet."));
|
||||||
m_lines << QString("Scheduled output: %1").arg(QDir::toNativeSeparators(outputName));
|
m_lines << qMakePair(timeStamp, QString());
|
||||||
m_lines << QString("Scheduled config: %1").arg(configName);
|
m_lines << qMakePair(timeStamp, QString("Scheduled source: %1").arg(QDir::toNativeSeparators(sourceName)));
|
||||||
|
m_lines << qMakePair(timeStamp, QString("Scheduled output: %1").arg(QDir::toNativeSeparators(outputName)));
|
||||||
|
m_lines << qMakePair(timeStamp, QString("Scheduled config: %1").arg(configName));
|
||||||
m_firstLine = true;
|
m_firstLine = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,7 +81,16 @@ QVariant LogFileModel::data(const QModelIndex &index, int role) const
|
|||||||
{
|
{
|
||||||
if(index.row() >= 0 && index.row() < m_lines.count() && index.column() == 0)
|
if(index.row() >= 0 && index.row() < m_lines.count() && index.column() == 0)
|
||||||
{
|
{
|
||||||
return m_lines.at(index.row());
|
if (role == Qt::ToolTipRole)
|
||||||
|
{
|
||||||
|
const LogEntry &entry = m_lines.at(index.row());
|
||||||
|
const QString timeStamp = QDateTime::fromMSecsSinceEpoch(entry.first).toString(FMT_TIMESTAMP);
|
||||||
|
return timeStamp + entry.second;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return m_lines.at(index.row()).second;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -89,8 +103,14 @@ QVariant LogFileModel::data(const QModelIndex &index, int role) const
|
|||||||
|
|
||||||
void LogFileModel::copyToClipboard(void)
|
void LogFileModel::copyToClipboard(void)
|
||||||
{
|
{
|
||||||
QClipboard *clipboard = QApplication::clipboard();
|
QClipboard *const clipboard = QApplication::clipboard();
|
||||||
clipboard->setText(m_lines.join("\r\n"));
|
QStringList buffer;
|
||||||
|
for (QList<LogEntry>::ConstIterator iter = m_lines.constBegin(); iter != m_lines.constEnd(); iter++)
|
||||||
|
{
|
||||||
|
const QString timeStamp = QDateTime::fromMSecsSinceEpoch(iter->first).toString(FMT_TIMESTAMP);
|
||||||
|
buffer << (timeStamp + iter->second);
|
||||||
|
}
|
||||||
|
clipboard->setText(buffer.join("\r\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LogFileModel::saveToLocalFile(const QString &fileName)
|
bool LogFileModel::saveToLocalFile(const QString &fileName)
|
||||||
@ -105,9 +125,10 @@ bool LogFileModel::saveToLocalFile(const QString &fileName)
|
|||||||
stream.setCodec("UTF-8");
|
stream.setCodec("UTF-8");
|
||||||
stream.setGenerateByteOrderMark(true);
|
stream.setGenerateByteOrderMark(true);
|
||||||
|
|
||||||
for(QStringList::ConstIterator iter = m_lines.constBegin(); iter != m_lines.constEnd(); iter++)
|
for(QList<LogEntry>::ConstIterator iter = m_lines.constBegin(); iter != m_lines.constEnd(); iter++)
|
||||||
{
|
{
|
||||||
stream << (*iter) << QLatin1String("\r\n");
|
const QString timeStamp = QDateTime::fromMSecsSinceEpoch(iter->first).toString(FMT_TIMESTAMP);
|
||||||
|
stream << timeStamp << iter->second << QLatin1String("\r\n");
|
||||||
if(stream.status() != QTextStream::Status::Ok)
|
if(stream.status() != QTextStream::Status::Ok)
|
||||||
{
|
{
|
||||||
file.close();
|
file.close();
|
||||||
@ -130,7 +151,7 @@ bool LogFileModel::saveToLocalFile(const QString &fileName)
|
|||||||
// Slots
|
// Slots
|
||||||
///////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
void LogFileModel::addLogMessage(const QUuid &jobId, const QString &text)
|
void LogFileModel::addLogMessage(const QUuid &jobId, const qint64 &timeStamp, const QString &text)
|
||||||
{
|
{
|
||||||
beginInsertRows(QModelIndex(), m_lines.count(), m_lines.count());
|
beginInsertRows(QModelIndex(), m_lines.count(), m_lines.count());
|
||||||
|
|
||||||
@ -140,10 +161,10 @@ void LogFileModel::addLogMessage(const QUuid &jobId, const QString &text)
|
|||||||
m_lines.clear();
|
m_lines.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList lines = text.split("\n");
|
const QStringList lines = text.split("\n");
|
||||||
for(int i = 0; i < lines.count(); i++)
|
for(QStringList::ConstIterator iter = lines.constBegin(); iter != lines.constEnd(); iter++)
|
||||||
{
|
{
|
||||||
m_lines.append(lines.at(i));
|
m_lines << qMakePair(timeStamp, (*iter));
|
||||||
}
|
}
|
||||||
|
|
||||||
endInsertRows();
|
endInsertRows();
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include "QAbstractItemModel"
|
#include "QAbstractItemModel"
|
||||||
#include <QUuid>
|
#include <QUuid>
|
||||||
#include <QStringList>
|
#include <QList>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
|
||||||
class LogFileModel : public QAbstractItemModel
|
class LogFileModel : public QAbstractItemModel
|
||||||
@ -47,9 +47,10 @@ public:
|
|||||||
bool saveToLocalFile(const QString &fileName);
|
bool saveToLocalFile(const QString &fileName);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QStringList m_lines;
|
|
||||||
bool m_firstLine;
|
bool m_firstLine;
|
||||||
|
typedef QPair<qint64, QString> LogEntry;
|
||||||
|
QList<LogEntry> m_lines;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void addLogMessage(const QUuid &jobId, const QString &text);
|
void addLogMessage(const QUuid &jobId, const qint64 &timeStamp, const QString &text);
|
||||||
};
|
};
|
||||||
|
@ -363,7 +363,7 @@ void EncodeThread::encode(void)
|
|||||||
|
|
||||||
void EncodeThread::log(const QString &text)
|
void EncodeThread::log(const QString &text)
|
||||||
{
|
{
|
||||||
emit messageLogged(m_jobId, text);
|
emit messageLogged(m_jobId, QDateTime::currentMSecsSinceEpoch(), text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EncodeThread::setStatus(const JobStatus &newStatus)
|
void EncodeThread::setStatus(const JobStatus &newStatus)
|
||||||
|
@ -111,7 +111,7 @@ protected:
|
|||||||
signals:
|
signals:
|
||||||
void statusChanged(const QUuid &jobId, const JobStatus &newStatus);
|
void statusChanged(const QUuid &jobId, const JobStatus &newStatus);
|
||||||
void progressChanged(const QUuid &jobId, const unsigned int &newProgress);
|
void progressChanged(const QUuid &jobId, const unsigned int &newProgress);
|
||||||
void messageLogged(const QUuid &jobId, const QString &text);
|
void messageLogged(const QUuid &jobId, qint64, const QString &text);
|
||||||
void detailsChanged(const QUuid &jobId, const QString &details);
|
void detailsChanged(const QUuid &jobId, const QString &details);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
#define VER_X264_MAJOR 2
|
#define VER_X264_MAJOR 2
|
||||||
#define VER_X264_MINOR 7
|
#define VER_X264_MINOR 7
|
||||||
#define VER_X264_PATCH 7
|
#define VER_X264_PATCH 7
|
||||||
#define VER_X264_BUILD 1066
|
#define VER_X264_BUILD 1069
|
||||||
|
|
||||||
#define VER_X264_PORTABLE_EDITION (0)
|
#define VER_X264_PORTABLE_EDITION (0)
|
||||||
|
|
||||||
|
@ -735,8 +735,15 @@ void MainWindow::saveLogFile(const QModelIndex &index)
|
|||||||
{
|
{
|
||||||
if(LogFileModel *log = m_jobList->getLogFile(index))
|
if(LogFileModel *log = m_jobList->getLogFile(index))
|
||||||
{
|
{
|
||||||
QDir(QString("%1/logs").arg(x264_data_path())).mkpath(".");
|
const QString outputDir = QString("%1/logs").arg(x264_data_path());
|
||||||
QString logFilePath = QString("%1/logs/LOG.%2.%3.txt").arg(x264_data_path(), QDate::currentDate().toString(Qt::ISODate), QTime::currentTime().toString(Qt::ISODate).replace(':', "-"));
|
const QString timeStamp = QDateTime::currentDateTime().toString("yyyy-MM-dd.HH-mm-ss");
|
||||||
|
QDir(outputDir).mkpath(".");
|
||||||
|
const QString logFilePath = MUtils::make_unique_file(outputDir, QString("LOG.%1").arg(timeStamp), QLatin1String("txt"));
|
||||||
|
if(logFilePath.isEmpty())
|
||||||
|
{
|
||||||
|
qWarning("Failed to generate log file name. Giving up!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
if(!log->saveToLocalFile(logFilePath))
|
if(!log->saveToLocalFile(logFilePath))
|
||||||
{
|
{
|
||||||
qWarning("Failed to open log file for writing:\n%s", logFilePath.toUtf8().constData());
|
qWarning("Failed to open log file for writing:\n%s", logFilePath.toUtf8().constData());
|
||||||
|
Loading…
Reference in New Issue
Block a user