Merge pull request #665 from flowln/logging_categories

This commit is contained in:
flow 2022-12-24 03:58:49 -08:00 committed by GitHub
commit 56ac1a0813
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 11 deletions

View File

@ -146,19 +146,12 @@ static const QLatin1String liveCheckFile("live.check");
PixmapCache* PixmapCache::s_instance = nullptr;
namespace {
/** This is used so that we can output to the log file in addition to the CLI. */
void appDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
const char *levels = "DWCFIS";
const QString format("%1 %2 %3\n");
qint64 msecstotal = APPLICATION->timeSinceStart();
qint64 seconds = msecstotal / 1000;
qint64 msecs = msecstotal % 1000;
QString foo;
char buf[1025] = {0};
::snprintf(buf, 1024, "%5lld.%03lld", seconds, msecs);
QString out = format.arg(buf).arg(levels[type]).arg(msg);
QString out = qFormatLogMessage(type, context, msg);
out += QChar::LineFeed;
APPLICATION->logFile->write(out.toUtf8());
APPLICATION->logFile->flush();
@ -431,6 +424,14 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv)
return;
}
qInstallMessageHandler(appDebugOutput);
qSetMessagePattern(
"%{time process}" " "
"%{if-debug}D%{endif}" "%{if-info}I%{endif}" "%{if-warning}W%{endif}" "%{if-critical}C%{endif}" "%{if-fatal}F%{endif}"
" " "|" " "
"%{if-category}[%{category}]: %{endif}"
"%{message}");
qDebug() << "<> Log initialized.";
}

View File

@ -41,6 +41,24 @@ Here are the current features of Prism Launcher.
*-a, --profile*=PROFILE
Use the account specified by PROFILE (only valid in combination with --launch).
# ENVIRONMENT
The behavior of the launcher can be customized by the following environment
variables, besides other common Qt variables:
*QT_LOGGING_RULES*
Specifies which logging categories are shown in the logs. One can
enable/disable multiple categories by separating them with a semicolon (;).
The specific syntax, and alternatives to this setting, can be found at
https://doc.qt.io/qt-6/qloggingcategory.html#configuring-categories.
*QT_MESSAGE_PATTERN*
Specifies the format in which the console output will be shown.
Available options, as well as syntax, can be viewed at
https://doc.qt.io/qt-6/qtglobal.html#qSetMessagePattern.
# EXIT STATUS
*0*