Reduce path to file in logs. Show only part inside of root folder.

This commit is contained in:
Roman Telezhynskyi 2024-04-09 19:22:19 +03:00
parent d331b5dc01
commit 3aec5bf341
5 changed files with 34 additions and 15 deletions

View File

@ -160,40 +160,41 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
{ {
QString debugdate = "["_L1 + QDateTime::currentDateTime().toString(QStringLiteral("yyyy.MM.dd hh:mm:ss")); QString debugdate = "["_L1 + QDateTime::currentDateTime().toString(QStringLiteral("yyyy.MM.dd hh:mm:ss"));
QString const file = VAbstractApplication::ReduceLogContextFilePath(context.file);
switch (type) switch (type)
{ {
case QtDebugMsg: case QtDebugMsg:
debugdate += QStringLiteral(":DEBUG:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":DEBUG:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, msg); .arg(context.function, context.category, msg);
vStdOut() << QApplication::translate("mNoisyHandler", "DEBUG:") << msg << "\n"; vStdOut() << QApplication::translate("mNoisyHandler", "DEBUG:") << msg << "\n";
break; break;
case QtWarningMsg: case QtWarningMsg:
debugdate += QStringLiteral(":WARNING:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":WARNING:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, msg); .arg(context.function, context.category, msg);
vStdErr() << QApplication::translate("mNoisyHandler", "WARNING:") << msg << "\n"; vStdErr() << QApplication::translate("mNoisyHandler", "WARNING:") << msg << "\n";
break; break;
case QtCriticalMsg: case QtCriticalMsg:
debugdate += QStringLiteral(":CRITICAL:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":CRITICAL:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, msg); .arg(context.function, context.category, msg);
vStdErr() << QApplication::translate("mNoisyHandler", "CRITICAL:") << msg << "\n"; vStdErr() << QApplication::translate("mNoisyHandler", "CRITICAL:") << msg << "\n";
break; break;
case QtFatalMsg: case QtFatalMsg:
debugdate += QStringLiteral(":FATAL:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":FATAL:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, msg); .arg(context.function, context.category, msg);
vStdErr() << QApplication::translate("mNoisyHandler", "FATAL:") << msg << "\n"; vStdErr() << QApplication::translate("mNoisyHandler", "FATAL:") << msg << "\n";
break; break;
case QtInfoMsg: case QtInfoMsg:
debugdate += QStringLiteral(":INFO:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":INFO:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, msg); .arg(context.function, context.category, msg);
vStdOut() << QApplication::translate("mNoisyHandler", "INFO:") << msg << "\n"; vStdOut() << QApplication::translate("mNoisyHandler", "INFO:") << msg << "\n";

View File

@ -196,40 +196,41 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
{ {
QString debugdate = "["_L1 + QDateTime::currentDateTime().toString(QStringLiteral("yyyy.MM.dd hh:mm:ss")); QString debugdate = "["_L1 + QDateTime::currentDateTime().toString(QStringLiteral("yyyy.MM.dd hh:mm:ss"));
QString const file = VAbstractApplication::ReduceLogContextFilePath(context.file);
switch (type) switch (type)
{ {
case QtDebugMsg: case QtDebugMsg:
debugdate += QStringLiteral(":DEBUG:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":DEBUG:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, logMsg); .arg(context.function, context.category, logMsg);
vStdOut() << QApplication::translate("mNoisyHandler", "DEBUG:") << logMsg << "\n"; vStdOut() << QApplication::translate("mNoisyHandler", "DEBUG:") << logMsg << "\n";
break; break;
case QtWarningMsg: case QtWarningMsg:
debugdate += QStringLiteral(":WARNING:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":WARNING:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, logMsg); .arg(context.function, context.category, logMsg);
vStdErr() << QApplication::translate("mNoisyHandler", "WARNING:") << logMsg << "\n"; vStdErr() << QApplication::translate("mNoisyHandler", "WARNING:") << logMsg << "\n";
break; break;
case QtCriticalMsg: case QtCriticalMsg:
debugdate += QStringLiteral(":CRITICAL:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":CRITICAL:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, logMsg); .arg(context.function, context.category, logMsg);
vStdErr() << QApplication::translate("mNoisyHandler", "CRITICAL:") << logMsg << "\n"; vStdErr() << QApplication::translate("mNoisyHandler", "CRITICAL:") << logMsg << "\n";
break; break;
case QtFatalMsg: case QtFatalMsg:
debugdate += QStringLiteral(":FATAL:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":FATAL:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, logMsg); .arg(context.function, context.category, logMsg);
vStdErr() << QApplication::translate("mNoisyHandler", "FATAL:") << logMsg << "\n"; vStdErr() << QApplication::translate("mNoisyHandler", "FATAL:") << logMsg << "\n";
break; break;
case QtInfoMsg: case QtInfoMsg:
debugdate += QStringLiteral(":INFO:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":INFO:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, logMsg); .arg(context.function, context.category, logMsg);
vStdOut() << QApplication::translate("mNoisyHandler", "INFO:") << logMsg << "\n"; vStdOut() << QApplication::translate("mNoisyHandler", "INFO:") << logMsg << "\n";

View File

@ -225,12 +225,13 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
{ {
QString debugdate = "["_L1 + QDateTime::currentDateTime().toString(QStringLiteral("yyyy.MM.dd hh:mm:ss")); QString debugdate = "["_L1 + QDateTime::currentDateTime().toString(QStringLiteral("yyyy.MM.dd hh:mm:ss"));
QString const file = VAbstractApplication::ReduceLogContextFilePath(context.file);
switch (type) switch (type)
{ {
case QtDebugMsg: case QtDebugMsg:
debugdate += QStringLiteral(":DEBUG:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":DEBUG:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, logMsg); .arg(context.function, context.category, logMsg);
vStdOut() << QApplication::translate("vNoisyHandler", "DEBUG:") << logMsg << "\n"; vStdOut() << QApplication::translate("vNoisyHandler", "DEBUG:") << logMsg << "\n";
@ -241,7 +242,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
VAbstractValApplication::VApp()->PostWarningMessage(logMsg, type); VAbstractValApplication::VApp()->PostWarningMessage(logMsg, type);
} }
debugdate += QStringLiteral(":WARNING:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":WARNING:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, logMsg); .arg(context.function, context.category, logMsg);
vStdErr() << QApplication::translate("vNoisyHandler", "WARNING:") << logMsg << "\n"; vStdErr() << QApplication::translate("vNoisyHandler", "WARNING:") << logMsg << "\n";
@ -252,14 +253,14 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
VAbstractValApplication::VApp()->PostWarningMessage(logMsg, type); VAbstractValApplication::VApp()->PostWarningMessage(logMsg, type);
} }
debugdate += QStringLiteral(":CRITICAL:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":CRITICAL:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, logMsg); .arg(context.function, context.category, logMsg);
vStdErr() << QApplication::translate("vNoisyHandler", "CRITICAL:") << logMsg << "\n"; vStdErr() << QApplication::translate("vNoisyHandler", "CRITICAL:") << logMsg << "\n";
break; break;
case QtFatalMsg: case QtFatalMsg:
debugdate += QStringLiteral(":FATAL:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":FATAL:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, logMsg); .arg(context.function, context.category, logMsg);
vStdErr() << QApplication::translate("vNoisyHandler", "FATAL:") << logMsg << "\n"; vStdErr() << QApplication::translate("vNoisyHandler", "FATAL:") << logMsg << "\n";
@ -270,7 +271,7 @@ inline void noisyFailureMsgHandler(QtMsgType type, const QMessageLogContext &con
VAbstractValApplication::VApp()->PostWarningMessage(logMsg, type); VAbstractValApplication::VApp()->PostWarningMessage(logMsg, type);
} }
debugdate += QStringLiteral(":INFO:%1(%2)] %3: %4: %5") debugdate += QStringLiteral(":INFO:%1(%2)] %3: %4: %5")
.arg(context.file) .arg(file)
.arg(context.line) .arg(context.line)
.arg(context.function, context.category, logMsg); .arg(context.function, context.category, logMsg);
vStdOut() << QApplication::translate("vNoisyHandler", "INFO:") << logMsg << "\n"; vStdOut() << QApplication::translate("vNoisyHandler", "INFO:") << logMsg << "\n";

View File

@ -287,6 +287,20 @@ auto VAbstractApplication::QtTranslationsPath(const QString &locale) -> QString
#endif // defined(Q_OS_LINUX) #endif // defined(Q_OS_LINUX)
} }
//---------------------------------------------------------------------------------------------------------------------
auto VAbstractApplication::ReduceLogContextFilePath(QString path) -> QString
{
// Find the position of the 'src' folder in the path
vsizetype const srcIndex = path.indexOf(QDir::toNativeSeparators(QStringLiteral("/src/")));
if (srcIndex != -1)
{
// Extract the substring starting from 'src' folder
path = path.mid(srcIndex);
}
return path;
}
//--------------------------------------------------------------------------------------------------------------------- //---------------------------------------------------------------------------------------------------------------------
auto VAbstractApplication::getUndoStack() const -> QUndoStack * auto VAbstractApplication::getUndoStack() const -> QUndoStack *
{ {

View File

@ -78,6 +78,8 @@ public:
static auto translationsPath(const QString &locale = QString()) -> QString; static auto translationsPath(const QString &locale = QString()) -> QString;
static auto QtTranslationsPath(const QString &locale = QString()) -> QString; static auto QtTranslationsPath(const QString &locale = QString()) -> QString;
static auto ReduceLogContextFilePath(QString path) -> QString;
void LoadTranslation(QString locale); void LoadTranslation(QString locale);
virtual void OpenSettings() = 0; virtual void OpenSettings() = 0;