diff options
author | flow <flowlnlnln@gmail.com> | 2022-08-18 21:32:57 -0300 |
---|---|---|
committer | flow <flowlnlnln@gmail.com> | 2022-12-22 19:15:50 -0300 |
commit | c85867395d310fa14a48f60eec17416b41fb486b (patch) | |
tree | 3bd36428cfce34ca90b09fe4e51b3b5b158a9f12 /launcher/Application.cpp | |
parent | bf2ce54076497cc9f89bdd92c4e2c5455217a18d (diff) | |
download | PrismLauncher-c85867395d310fa14a48f60eec17416b41fb486b.tar.gz PrismLauncher-c85867395d310fa14a48f60eec17416b41fb486b.tar.bz2 PrismLauncher-c85867395d310fa14a48f60eec17416b41fb486b.zip |
feat: use Qt logging facilities instead of our own
This system allows us to globally define categories, and control whether
they are shown or not at runtime. It also does some things by it's own,
so we can remove some (uhhh) code.
Lastly, this allows changing the behavior of the logger at runtime via
environment variables that Qt takes care of for us.
Signed-off-by: flow <flowlnlnln@gmail.com>
Diffstat (limited to 'launcher/Application.cpp')
-rw-r--r-- | launcher/Application.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/launcher/Application.cpp b/launcher/Application.cpp index 3f313ee4..eef4fd7a 100644 --- a/launcher/Application.cpp +++ b/launcher/Application.cpp @@ -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,15 @@ Application::Application(int &argc, char **argv) : QApplication(argc, argv) return; } qInstallMessageHandler(appDebugOutput); + + // TODO: Set filter rules based on CLI arguments + 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."; } |