diff options
| author | Petr Mrázek <peterix@gmail.com> | 2015-02-02 02:14:14 +0100 |
|---|---|---|
| committer | Petr Mrázek <peterix@gmail.com> | 2015-04-12 20:57:17 +0200 |
| commit | cd9d37aac402b0edd0f12b66fd7f2fdd5fe6dff5 (patch) | |
| tree | d8dd6499e29fbf5196b0d5a20f0a0da386b575bb | |
| parent | 28a39ef7ac3e3dfe4ea65d02af01d1a18e3d4af6 (diff) | |
| download | PrismLauncher-cd9d37aac402b0edd0f12b66fd7f2fdd5fe6dff5.tar.gz PrismLauncher-cd9d37aac402b0edd0f12b66fd7f2fdd5fe6dff5.tar.bz2 PrismLauncher-cd9d37aac402b0edd0f12b66fd7f2fdd5fe6dff5.zip | |
SCRATCH nuke the overcomplicated logger, use a simple one.
71 files changed, 415 insertions, 934 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 1229bcfa..3751da3c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,14 +270,6 @@ SET(MULTIMC_SOURCES BuildConfig.h ${PROJECT_BINARY_DIR}/BuildConfig.cpp - # Logging - logger/QsDebugOutput.cpp - logger/QsDebugOutput.h - logger/QsLog.cpp - logger/QsLog.h - logger/QsLogDest.cpp - logger/QsLogDest.h - # GUI - general utilities gui/GuiUtil.h gui/GuiUtil.cpp @@ -1,7 +1,7 @@ #pragma once #include <exception> #include <QString> -#include <logger/QsLog.h> +#include <QDebug> class MMCError : public std::exception { @@ -9,7 +9,7 @@ public: MMCError(QString cause) { exceptionCause = cause; - QLOG_ERROR() << "Exception: " + cause; + qCritical() << "Exception: " + cause; }; virtual ~MMCError() noexcept {} virtual const char *what() const noexcept diff --git a/MultiMC.cpp b/MultiMC.cpp index e3319c9a..03131008 100644 --- a/MultiMC.cpp +++ b/MultiMC.cpp @@ -10,6 +10,7 @@ #include <QMessageBox> #include <QStringList> #include <QDesktopServices> +#include <QDebug> #include "gui/dialogs/VersionSelectDialog.h" #include "logic/InstanceList.h" @@ -38,8 +39,7 @@ #include <xdgicon.h> #include "logic/settings/INISettingsObject.h" #include "logic/settings/Setting.h" -#include "logger/QsLog.h" -#include "logger/QsLogDest.h" + #include "logic/trans/TranslationDownloader.h" @@ -52,6 +52,8 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar setOrganizationName("MultiMC"); setApplicationName("MultiMC5"); + startTime = QDateTime::currentDateTime(); + setAttribute(Qt::AA_UseHighDpiPixmaps); // Don't quit on hiding the last window this->setQuitOnLastWindowClosed(false); @@ -129,7 +131,7 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar { // BAD STUFF. WHAT DO? initLogger(); - QLOG_ERROR() << "Failed to set work path. Will exit. NOW."; + qCritical() << "Failed to set work path. Will exit. NOW."; m_status = MultiMC::Failed; return; } @@ -166,22 +168,22 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar // init the logger initLogger(); - QLOG_INFO() << "MultiMC 5, (c) 2013-2015 MultiMC Contributors"; - QLOG_INFO() << "Version : " << BuildConfig.VERSION_STR; - QLOG_INFO() << "Git commit : " << BuildConfig.GIT_COMMIT; + qDebug() << "MultiMC 5, (c) 2013-2015 MultiMC Contributors"; + qDebug() << "Version : " << BuildConfig.VERSION_STR; + qDebug() << "Git commit : " << BuildConfig.GIT_COMMIT; if (adjustedBy.size()) { - QLOG_INFO() << "Work dir before adjustment : " << origcwdPath; - QLOG_INFO() << "Work dir after adjustment : " << QDir::currentPath(); - QLOG_INFO() << "Adjusted by : " << adjustedBy; + qDebug() << "Work dir before adjustment : " << origcwdPath; + qDebug() << "Work dir after adjustment : " << QDir::currentPath(); + qDebug() << "Adjusted by : " << adjustedBy; } else { - QLOG_INFO() << "Work dir : " << QDir::currentPath(); + qDebug() << "Work dir : " << QDir::currentPath(); } - QLOG_INFO() << "Binary path : " << binPath; - QLOG_INFO() << "Application root path : " << rootPath; - QLOG_INFO() << "Static data path : " << staticDataPath; + qDebug() << "Binary path : " << binPath; + qDebug() << "Application root path : " << rootPath; + qDebug() << "Static data path : " << staticDataPath; // load settings initGlobalSettings(test_mode); @@ -202,21 +204,21 @@ MultiMC::MultiMC(int &argc, char **argv, bool test_mode) : QApplication(argc, ar // instance path: check for problems with '!' in instance path and warn the user in the log // and rememer that we have to show him a dialog when the gui starts (if it does so) QString instDir = m_settings->get("InstanceDir").toString(); - QLOG_INFO() << "Instance path : " << instDir; + qDebug() << "Instance path : " << instDir; if (checkProblemticPathJava(QDir(instDir))) { - QLOG_WARN() + qWarning() << "Your instance path contains \'!\' and this is known to cause java problems"; } m_instances.reset(new InstanceList(m_settings, InstDirSetting->get().toString(), this)); - QLOG_INFO() << "Loading Instances..."; + qDebug() << "Loading Instances..."; m_instances->loadList(); connect(InstDirSetting.get(), SIGNAL(SettingChanged(const Setting &, QVariant)), m_instances.get(), SLOT(on_InstFolderChanged(const Setting &, QVariant))); // and accounts m_accounts.reset(new MojangAccountList(this)); - QLOG_INFO() << "Loading accounts..."; + qDebug() << "Loading accounts..."; m_accounts->setListFilePath("accounts.json", true); m_accounts->loadList(); @@ -275,16 +277,16 @@ void MultiMC::initTranslations() { QLocale locale(m_settings->get("Language").toString()); QLocale::setDefault(locale); - QLOG_INFO() << "Your language is" << locale.bcp47Name(); + qDebug() << "Your language is" << locale.bcp47Name(); m_qt_translator.reset(new QTranslator()); if (m_qt_translator->load("qt_" + locale.bcp47Name(), QLibraryInfo::location(QLibraryInfo::TranslationsPath))) { - QLOG_DEBUG() << "Loading Qt Language File for" + qDebug() << "Loading Qt Language File for" << locale.bcp47Name().toLocal8Bit().constData() << "..."; if (!installTranslator(m_qt_translator.get())) { - QLOG_ERROR() << "Loading Qt Language File failed."; + qCritical() << "Loading Qt Language File failed."; m_qt_translator.reset(); } } @@ -296,11 +298,11 @@ void MultiMC::initTranslations() m_mmc_translator.reset(new QTranslator()); if (m_mmc_translator->load("mmc_" + locale.bcp47Name(), staticDataPath + "/translations")) { - QLOG_DEBUG() << "Loading MMC Language File for" + qDebug() << "Loading MMC Language File for" << locale.bcp47Name().toLocal8Bit().constData() << "..."; if (!installTranslator(m_mmc_translator.get())) { - QLOG_ERROR() << "Loading MMC Language File failed."; + qCritical() << "Loading MMC Language File failed."; m_mmc_translator.reset(); } } @@ -327,6 +329,28 @@ void moveFile(const QString &oldName, const QString &newName) QFile::copy(oldName, newName); QFile::remove(oldName); } + + +void appDebugOutput(QtMsgType type, const QMessageLogContext &context, const QString &msg) +{ + const char *levels = "DWCF"; + const QString format("%1 %2 %3\n"); + + qint64 msecstotal = MMC->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); + + MMC->logFile->write(out.toUtf8()); + MMC->logFile->flush(); + QTextStream(stderr) << out.toLocal8Bit(); + fflush(stderr); +} + void MultiMC::initLogger() { static const QString logBase = "MultiMC-%0.log"; @@ -336,15 +360,10 @@ void MultiMC::initLogger() moveFile(logBase.arg(1), logBase.arg(2)); moveFile(logBase.arg(0), logBase.arg(1)); - // init the logging mechanism - QsLogging::Logger &logger = QsLogging::Logger::instance(); - logger.setLoggingLevel(QsLogging::TraceLevel); - m_fileDestination = QsLogging::DestinationFactory::MakeFileDestination(logBase.arg(0)); - m_debugDestination = QsLogging::DestinationFactory::MakeDebugOutputDestination(); - logger.addDestination(m_fileDestination.get()); - logger.addDestination(m_debugDestination.get()); - // log all the things - logger.setLoggingLevel(QsLogging::TraceLevel); + qInstallMessageHandler(appDebugOutput); + + logFile = std::make_shared<QFile>(logBase.arg(0)); + logFile->open(QIODevice::WriteOnly | QIODevice::Text | QIODevice::Truncate); } void MultiMC::initGlobalSettings(bool test_mode) @@ -381,7 +400,7 @@ void MultiMC::initGlobalSettings(bool test_mode) QFontInfo consoleFontInfo(consoleFont); QString resolvedDefaultMonospace = consoleFontInfo.family(); QFont resolvedFont(resolvedDefaultMonospace); - QLOG_DEBUG() << "Detected default console font:" << resolvedDefaultMonospace + qDebug() << "Detected default console font:" << resolvedDefaultMonospace << ", substitutions:" << resolvedFont.substitutions().join(','); m_settings->registerSetting("ConsoleFont", resolvedDefaultMonospace); } @@ -527,7 +546,7 @@ void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags) m_updateOnExitFlags = None; m_updateOnExitPath.clear(); } - QLOG_INFO() << "Installing updates."; + qDebug() << "Installing updates."; #ifdef WINDOWS QString finishCmd = applicationFilePath(); QString updaterBinary = PathCombine(applicationDirPath(), "updater.exe"); @@ -555,12 +574,12 @@ void MultiMC::installUpdates(const QString updateFilesDir, UpdateFlags flags) args << "--finish-cmd" << finishCmd; args << "--finish-dir" << dataPath; } - QLOG_INFO() << "Running updater with command" << updaterBinary << args.join(" "); + qDebug() << "Running updater with command" << updaterBinary << args.join(" "); QFile::setPermissions(updaterBinary, (QFileDevice::Permission)0x7755); if (!QProcess::startDetached(updaterBinary, args /*, root()*/)) { - QLOG_ERROR() << "Failed to start the updater process!"; + qCritical() << "Failed to start the updater process!"; return; } @@ -590,6 +609,11 @@ void MultiMC::onExit() installUpdates(m_updateOnExitPath, m_updateOnExitFlags); } ENV.destroy(); + if(logFile) + { + logFile->flush(); + logFile->close(); + } } bool MultiMC::openJsonEditor(const QString &filename) @@ -2,11 +2,12 @@ #include <QApplication> #include <memory> -#include "logger/QsLog.h" -#include "logger/QsLogDest.h" +#include <QDebug> #include <QFlag> #include <QIcon> +#include <QDateTime> +class QFile; class MinecraftVersionList; class LWJGLVersionList; class HttpMetaCache; @@ -62,7 +63,10 @@ public: return m_settings; } - + qint64 timeSinceStart() const + { + return startTime.msecsTo(QDateTime::currentDateTime()); + } QIcon getThemedIcon(const QString& name); @@ -153,6 +157,8 @@ private: friend class UpdateCheckerTest; friend class DownloadUpdateTaskTest; + QDateTime startTime; + std::shared_ptr<QTranslator> m_qt_translator; std::shared_ptr<QTranslator> m_mmc_translator; std::shared_ptr<SettingsObject> m_settings; @@ -169,9 +175,6 @@ private: QMap<QString, std::shared_ptr<BaseProfilerFactory>> m_profilers; QMap<QString, std::shared_ptr<BaseDetachedToolFactory>> m_tools; - QsLogging::DestinationPtr m_fileDestination; - QsLogging::DestinationPtr m_debugDestination; - QString m_updateOnExitPath; UpdateFlags m_updateOnExitFlags = None; @@ -180,4 +183,6 @@ private: QString dataPath; Status m_status = MultiMC::Failed; +public: + std::shared_ptr<QFile> logFile; }; diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index f0d882ba..2025a097 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -916,7 +916,7 @@ void MainWindow::updateAvailable(QString repo, QString versionName, int versionI switch (action) { case UPDATE_LATER: - QLOG_INFO() << "Update will be installed later."; + qDebug() << "Update will be installed later."; break; case UPDATE_NOW: downloadUpdates(repo, versionId); @@ -975,7 +975,7 @@ void MainWindow::notificationsChanged() void MainWindow::downloadUpdates(QString repo, int versionId, bool installOnExit) { - QLOG_INFO() << "Downloading updates."; + qDebug() << "Downloading updates."; // TODO: If the user chooses to update on exit, we should download updates in the // background. // Doing so is a bit complicated, because we'd have to make sure it finished downloading @@ -1086,7 +1086,7 @@ void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QStrin QTemporaryDir extractTmpDir; QDir extractDir(extractTmpDir.path()); - QLOG_INFO() << "Attempting to create instance from" << archivePath; + qDebug() << "Attempting to create instance from" << archivePath; if (JlCompress::extractDir(archivePath, extractDir.absolutePath()).isEmpty()) { CustomMessageBox::selectable(this, tr("Error"), @@ -1730,7 +1730,7 @@ void MainWindow::doLaunch(bool online, BaseProfilerFactory *profiler) { case AuthSession::Undetermined: { - QLOG_ERROR() << "Received undetermined session status during login. Bye."; + qCritical() << "Received undetermined session status during login. Bye."; tryagain = false; break; } @@ -2004,7 +2004,7 @@ void MainWindow::checkSetDefaultJava() if (askForJava) { - QLOG_DEBUG() << "Java path needs resetting, showing Java selection dialog..."; + qDebug() << "Java path needs resetting, showing Java selection dialog..."; JavaVersionPtr java; diff --git a/gui/dialogs/AccountSelectDialog.cpp b/gui/dialogs/AccountSelectDialog.cpp index 4d10112e..6ae60738 100644 --- a/gui/dialogs/AccountSelectDialog.cpp +++ b/gui/dialogs/AccountSelectDialog.cpp @@ -18,7 +18,7 @@ #include <QItemSelectionModel> -#include <logger/QsLog.h> +#include <QDebug> #include <gui/dialogs/ProgressDialog.h> @@ -40,7 +40,7 @@ AccountSelectDialog::AccountSelectDialog(const QString &message, int flags, QWid // Flags... ui->globalDefaultCheck->setVisible(flags & GlobalDefaultCheckbox); ui->instDefaultCheck->setVisible(flags & InstanceDefaultCheckbox); - QLOG_DEBUG() << flags; + qDebug() << flags; // Select the first entry in the list. ui->listView->setCurrentIndex(ui->listView->model()->index(0, 0)); diff --git a/gui/dialogs/UpdateDialog.cpp b/gui/dialogs/UpdateDialog.cpp index 29d09ead..1fcc156a 100644 --- a/gui/dialogs/UpdateDialog.cpp +++ b/gui/dialogs/UpdateDialog.cpp @@ -1,7 +1,7 @@ #include "UpdateDialog.h" #include "ui_UpdateDialog.h" #include "gui/Platform.h" -#include "logger/QsLog.h" +#include <QDebug> #include "MultiMC.h" #include <logic/settings/SettingsObject.h> @@ -82,7 +82,7 @@ QString reprocessMarkdown(QString markdown) html << "<ul>\n"; html << "<li>" << procLine(line.mid(2)) << "</li>\n"; } - else QLOG_ERROR() << "Invalid input on line " << i << ": " << line; + else qCritical() << "Invalid input on line " << i << ": " << line; break; case LIST1: if(line.startsWith("##")) @@ -107,7 +107,7 @@ QString reprocessMarkdown(QString markdown) html << "<ul>\n"; html << "<li>" << procLine(line.mid(4)) << "</li>\n"; } - else QLOG_ERROR() << "Invalid input on line " << i << ": " << line; + else qCritical() << "Invalid input on line " << i << ": " << line; break; case LIST2: if(line.startsWith("##")) @@ -134,7 +134,7 @@ QString reprocessMarkdown(QString markdown) { html << "<li>" << procLine(line.mid(4)) << "</li>\n"; } - else QLOG_ERROR() << "Invalid input on line " << i << ": " << line; + else qCritical() << "Invalid input on line " << i << ": " << line; break; } i++; @@ -151,10 +151,10 @@ QString reprocessMarkdown(QString markdown) } if (state != BASE) { - QLOG_ERROR() << "Reprocessing markdown didn't end in a final state!"; + qCritical() << "Reprocessing markdown didn't end in a final state!"; } html << "</html>\n"; - QLOG_DEBUG() << htmlData; + qDebug() << htmlData; return htmlData; } diff --git a/gui/dialogs/VersionSelectDialog.cpp b/gui/dialogs/VersionSelectDialog.cpp index e9758d55..a0a58699 100644 --- a/gui/dialogs/VersionSelectDialog.cpp +++ b/gui/dialogs/VersionSelectDialog.cpp @@ -25,7 +25,7 @@ #include <logic/BaseVersionList.h> #include <logic/tasks/Task.h> #include <depends/util/include/modutils.h> -#include "logger/QsLog.h" +#include <QDebug> class VersionSelectProxyModel : public QSortFilterProxyModel { diff --git a/gui/groupview/GroupView.cpp b |
