Each Valentina's process have own log file.
--HG-- branch : develop
This commit is contained in:
parent
b48f9032f9
commit
b5f119558d
|
@ -48,6 +48,7 @@
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QLoggingCategory>
|
#include <QLoggingCategory>
|
||||||
|
#include <QLockFile>
|
||||||
|
|
||||||
Q_LOGGING_CATEGORY(vApp, "v.application")
|
Q_LOGGING_CATEGORY(vApp, "v.application")
|
||||||
|
|
||||||
|
@ -85,29 +86,33 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
|
||||||
|
|
||||||
if (isGuiThread)
|
if (isGuiThread)
|
||||||
{
|
{
|
||||||
QString debugdate = QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss");
|
QString debugdate = "[" + QDateTime::currentDateTime().toString("yyyy.MM.dd hh:mm:ss");
|
||||||
QMessageBox messageBox;
|
QMessageBox messageBox;
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case QtDebugMsg:
|
case QtDebugMsg:
|
||||||
debugdate += QString(" [Debug] %1: \"%2\" %3").arg(context.category).arg(msg).arg(context.function);
|
debugdate += QString(":DEBUG:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
|
||||||
|
.arg(context.function).arg(context.category).arg(msg);
|
||||||
break;
|
break;
|
||||||
case QtWarningMsg:
|
case QtWarningMsg:
|
||||||
debugdate += QString(" [Warning] %1: \"%2\" %3").arg(context.category).arg(msg).arg(context.function);
|
debugdate += QString(":WARNING:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
|
||||||
|
.arg(context.function).arg(context.category).arg(msg);
|
||||||
messageBox.setIcon(QMessageBox::Warning);
|
messageBox.setIcon(QMessageBox::Warning);
|
||||||
messageBox.setInformativeText(msg);
|
messageBox.setInformativeText(msg);
|
||||||
messageBox.setStandardButtons(QMessageBox::Ok);
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
||||||
messageBox.exec();
|
messageBox.exec();
|
||||||
break;
|
break;
|
||||||
case QtCriticalMsg:
|
case QtCriticalMsg:
|
||||||
debugdate += QString(" [Critical] %1: \"%2\" %3").arg(context.category).arg(msg).arg(context.function);
|
debugdate += QString(":CRITICAL:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
|
||||||
|
.arg(context.function).arg(context.category).arg(msg);
|
||||||
messageBox.setIcon(QMessageBox::Critical);
|
messageBox.setIcon(QMessageBox::Critical);
|
||||||
messageBox.setInformativeText(msg);
|
messageBox.setInformativeText(msg);
|
||||||
messageBox.setStandardButtons(QMessageBox::Ok);
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
||||||
messageBox.exec();
|
messageBox.exec();
|
||||||
break;
|
break;
|
||||||
case QtFatalMsg:
|
case QtFatalMsg:
|
||||||
debugdate += QString(" [Fatal] %1: \"%2\" %3").arg(context.category).arg(msg).arg(context.function);
|
debugdate += QString(":FATAL:%1(%2)] %3: %4: %5").arg(context.file).arg(context.line)
|
||||||
|
.arg(context.function).arg(context.category).arg(msg);
|
||||||
messageBox.setIcon(QMessageBox::Critical);
|
messageBox.setIcon(QMessageBox::Critical);
|
||||||
messageBox.setInformativeText(msg);
|
messageBox.setInformativeText(msg);
|
||||||
messageBox.setStandardButtons(QMessageBox::Ok);
|
messageBox.setStandardButtons(QMessageBox::Ok);
|
||||||
|
@ -156,7 +161,7 @@ VApplication::VApplication(int &argc, char **argv)
|
||||||
variables(QMap<QString, VTranslation>()), functions(QMap<QString, VTranslation>()),
|
variables(QMap<QString, VTranslation>()), functions(QMap<QString, VTranslation>()),
|
||||||
postfixOperators(QMap<QString, VTranslation>()), stDescriptions(QMap<QString, VTranslation>()),
|
postfixOperators(QMap<QString, VTranslation>()), stDescriptions(QMap<QString, VTranslation>()),
|
||||||
undoStack(nullptr), sceneView(nullptr), currentScene(nullptr), autoSaveTimer(nullptr), mainWindow(nullptr),
|
undoStack(nullptr), sceneView(nullptr), currentScene(nullptr), autoSaveTimer(nullptr), mainWindow(nullptr),
|
||||||
openingPattern(false), settings(nullptr), doc(nullptr), log(nullptr), out(nullptr)
|
openingPattern(false), settings(nullptr), doc(nullptr), log(nullptr), out(nullptr), logLock(nullptr)
|
||||||
{
|
{
|
||||||
undoStack = new QUndoStack(this);
|
undoStack = new QUndoStack(this);
|
||||||
|
|
||||||
|
@ -179,6 +184,7 @@ VApplication::~VApplication()
|
||||||
{
|
{
|
||||||
log->close();
|
log->close();
|
||||||
delete log;
|
delete log;
|
||||||
|
delete logLock;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -434,7 +440,86 @@ QString VApplication::LogDirPath() const
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
QString VApplication::LogPath() const
|
QString VApplication::LogPath() const
|
||||||
{
|
{
|
||||||
return LogDirPath() + "/valentina.log";
|
return QString("%1/valentina-pid%2.log").arg(LogDirPath()).arg(qApp->applicationPid());
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VApplication::CreateLogDir() const
|
||||||
|
{
|
||||||
|
QDir logDir(LogDirPath());
|
||||||
|
if (logDir.exists() == false)
|
||||||
|
{
|
||||||
|
logDir.mkpath("."); // Create directory for log if need
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VApplication::BeginLogging()
|
||||||
|
{
|
||||||
|
log = new QFile(LogPath());
|
||||||
|
if (log->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
|
||||||
|
{
|
||||||
|
out = new QTextStream(log);
|
||||||
|
qInstallMessageHandler(noisyFailureMsgHandler);
|
||||||
|
logLock = new QLockFile(LogPath()+".lock");
|
||||||
|
logLock->setStaleLockTime(0);
|
||||||
|
if (logLock->tryLock())
|
||||||
|
{
|
||||||
|
qCDebug(vApp) << "Log file"<<LogPath()<<"was locked.";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCDebug(vApp) << "Failed to lock" << LogPath();
|
||||||
|
qCDebug(vApp) << "Error type:"<<logLock->error();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
delete log;
|
||||||
|
qCDebug(vApp) << "Error opening log file '" << LogPath() << "'. All debug output redirected to console.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
void VApplication::ClearOldLogs() const
|
||||||
|
{
|
||||||
|
QStringList filters{"*.log"};
|
||||||
|
QDir logsDir(LogDirPath());
|
||||||
|
logsDir.setNameFilters(filters);
|
||||||
|
logsDir.setCurrent(LogDirPath());
|
||||||
|
|
||||||
|
const QStringList allFiles = logsDir.entryList(QDir::NoDotAndDotDot | QDir::Files);
|
||||||
|
if (allFiles.isEmpty() == false)
|
||||||
|
{
|
||||||
|
qCDebug(vApp) << "Clearing old logs";
|
||||||
|
for (int i = 0; i < allFiles.size(); ++i)
|
||||||
|
{
|
||||||
|
QFileInfo info(allFiles.at(i));
|
||||||
|
QLockFile *lock = new QLockFile(info.absoluteFilePath() + ".lock");
|
||||||
|
if (lock->tryLock())
|
||||||
|
{
|
||||||
|
qCDebug(vApp) << "Locked file"<<info.absoluteFilePath();
|
||||||
|
QFile oldLog(allFiles.at(i));
|
||||||
|
if (oldLog.remove())
|
||||||
|
{
|
||||||
|
qCDebug(vApp) << "Deleted"<<info.absoluteFilePath();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCDebug(vApp) << "Could not delete"<<info.absoluteFilePath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCDebug(vApp) << "Failed to lock"<<info.absoluteFilePath();
|
||||||
|
}
|
||||||
|
delete lock;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
qCDebug(vApp) << "There are no old logs.";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
@ -2004,23 +2089,9 @@ void VApplication::StartLogging()
|
||||||
QLoggingCategory::setFilterRules("*.debug=true\n");
|
QLoggingCategory::setFilterRules("*.debug=true\n");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QDir logDir(LogDirPath());
|
CreateLogDir();
|
||||||
if (logDir.exists() == false)
|
BeginLogging();
|
||||||
{
|
ClearOldLogs();
|
||||||
logDir.mkpath("."); // Create directory for log if need
|
|
||||||
}
|
|
||||||
|
|
||||||
log = new QFile(LogPath());
|
|
||||||
if (log->open(QIODevice::WriteOnly | QIODevice::Truncate | QIODevice::Text))
|
|
||||||
{
|
|
||||||
out = new QTextStream(log);
|
|
||||||
qInstallMessageHandler(noisyFailureMsgHandler);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
delete log;
|
|
||||||
qDebug() << "Error opening log file '" << LogPath() << "'. All debug output redirected to console.";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -41,6 +41,7 @@ class VMainGraphicsScene;
|
||||||
class VPattern;
|
class VPattern;
|
||||||
class QFile;
|
class QFile;
|
||||||
class VSettings;
|
class VSettings;
|
||||||
|
class QLockFile;
|
||||||
|
|
||||||
#if defined(qApp)
|
#if defined(qApp)
|
||||||
#undef qApp
|
#undef qApp
|
||||||
|
@ -154,6 +155,7 @@ private:
|
||||||
VPattern *doc;
|
VPattern *doc;
|
||||||
QFile *log;
|
QFile *log;
|
||||||
QTextStream *out;
|
QTextStream *out;
|
||||||
|
QLockFile *logLock;
|
||||||
void InitLineWidth();
|
void InitLineWidth();
|
||||||
void InitMeasurements();
|
void InitMeasurements();
|
||||||
void InitVariables();
|
void InitVariables();
|
||||||
|
@ -182,6 +184,9 @@ private:
|
||||||
|
|
||||||
QString LogDirPath()const;
|
QString LogDirPath()const;
|
||||||
QString LogPath()const;
|
QString LogPath()const;
|
||||||
|
void CreateLogDir()const;
|
||||||
|
void BeginLogging();
|
||||||
|
void ClearOldLogs()const;
|
||||||
};
|
};
|
||||||
|
|
||||||
//---------------------------------------------------------------------------------------------------------------------
|
//---------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
|
@ -73,6 +73,7 @@ int main(int argc, char *argv[])
|
||||||
qDebug()<<"Based on Qt "<<QT_VERSION_STR<<"(32 bit)";
|
qDebug()<<"Based on Qt "<<QT_VERSION_STR<<"(32 bit)";
|
||||||
qDebug()<<"Built on"<<__DATE__<<"at"<<__TIME__;
|
qDebug()<<"Built on"<<__DATE__<<"at"<<__TIME__;
|
||||||
qDebug()<<"Command-line arguments:"<<app.arguments();
|
qDebug()<<"Command-line arguments:"<<app.arguments();
|
||||||
|
qDebug()<<"Process ID:"<<app.applicationPid();
|
||||||
|
|
||||||
const QString checkedLocale = qApp->getSettings()->GetLocale();
|
const QString checkedLocale = qApp->getSettings()->GetLocale();
|
||||||
qDebug()<<"Checked locale:"<<checkedLocale;
|
qDebug()<<"Checked locale:"<<checkedLocale;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user