1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

chore: Shorten source file names in log messages.

In cmake builds, `__FILE__` is the absolute file path. In qmake, it's a
relative path. For in-tree qmake builds, it would be `"src/..."`, for
out of tree, it could be `"../src/..."` or `"../qTox/src/..."` or any
other relative path depending on how qTox was built. This change
normalises them to paths based in src.
This commit is contained in:
iphydf 2016-09-04 17:17:44 +01:00
parent 76c4cf7d39
commit 153ebb339d
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9

View File

@ -58,10 +58,20 @@ void logMessageHandler(QtMsgType type, const QMessageLogContext& ctxt, const QSt
&& msg == QString("QFSFileEngine::open: No file name specified"))
return;
QString file = ctxt.file;
// We're not using QT_MESSAGELOG_FILE here, because that can be 0, NULL, or
// nullptr in release builds.
QString path = QString(__FILE__);
path = path.left(path.lastIndexOf('/') + 1);
if (file.startsWith(path))
{
file = file.mid(path.length());
}
// Time should be in UTC to save user privacy on log sharing
QTime time = QDateTime::currentDateTime().toUTC().time();
QString LogMsg = QString("[%1 UTC] %2:%3 : ")
.arg(time.toString("HH:mm:ss.zzz")).arg(ctxt.file).arg(ctxt.line);
.arg(time.toString("HH:mm:ss.zzz")).arg(file).arg(ctxt.line);
switch (type)
{
case QtDebugMsg: