summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorisanae <14251494+isanae@users.noreply.github.com>2019-07-17 11:00:47 -0400
committerisanae <14251494+isanae@users.noreply.github.com>2019-07-22 07:33:38 -0400
commit4dfaa363c05eb7691e2c7ea755c35758b62e0fc9 (patch)
tree616ca742354155d454dab50bd4b8be7b5f86a613 /src/main.cpp
parentad77e315f5c53994d75056608df0f9ff0a390530 (diff)
logging initialized early, log file set later
replaced a few qDebug()
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp80
1 files changed, 44 insertions, 36 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 65f4bd05..f55c32f2 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -253,17 +253,17 @@ QString determineProfile(QStringList &arguments, const QSettings &settings)
{ // see if there is a profile on the command line
int profileIndex = arguments.indexOf("-p", 1);
if ((profileIndex != -1) && (profileIndex < arguments.size() - 1)) {
- qDebug("profile overwritten on command line");
+ log::debug("profile overwritten on command line");
selectedProfileName = arguments.at(profileIndex + 1);
}
arguments.removeAt(profileIndex);
arguments.removeAt(profileIndex);
}
if (selectedProfileName.isEmpty()) {
- qDebug("no configured profile");
+ log::debug("no configured profile");
selectedProfileName = "Default";
} else {
- qDebug("configured profile: %s", qUtf8Printable(selectedProfileName));
+ log::debug("configured profile: {}", selectedProfileName);
}
return selectedProfileName;
@@ -425,8 +425,7 @@ void setupPath()
{
static const int BUFSIZE = 4096;
- qDebug("MO at: %s", qUtf8Printable(QDir::toNativeSeparators(
- QCoreApplication::applicationDirPath())));
+ log::debug("MO at {}", QCoreApplication::applicationDirPath());
QCoreApplication::setLibraryPaths(QStringList(QCoreApplication::applicationDirPath() + "/dlls") + QCoreApplication::libraryPaths());
@@ -447,7 +446,7 @@ void setupPath()
void preloadDll(const QString& filename)
{
- qDebug().nospace() << "preloading " << filename;
+ log::debug("preloading {}", filename);
if (GetModuleHandleW(filename.toStdWString().c_str())) {
// already loaded, this can happen when "restarting" MO by switching
@@ -490,41 +489,43 @@ static QString getVersionDisplayString()
return createVersionInfo().displayString(3);
}
+void dumpEnvironment()
+{
+ env::Environment env;
+
+ log::debug("windows: {}", env.windowsInfo().toString());
+
+ if (env.windowsInfo().compatibilityMode()) {
+ log::warn("MO seems to be running in compatibility mode");
+ }
+
+ log::debug("security products:");
+ for (const auto& sp : env.securityProducts()) {
+ log::debug(" . {}", sp.toString());
+ }
+
+ log::debug("modules loaded in process:");
+ for (const auto& m : env.loadedModules()) {
+ log::debug(" . {}", m.toString());
+ }
+}
+
int runApplication(MOApplication &application, SingleInstance &instance,
const QString &splashPath)
{
- qDebug().nospace()
- << "Starting Mod Organizer version "
- << getVersionDisplayString() << " revision " << GITID;
+ log::info(
+ "Starting Mod Organizer version {} revision {}",
+ getVersionDisplayString(), GITID);
#if !defined(QT_NO_SSL)
preloadSsl();
- qDebug("ssl support: %d", QSslSocket::supportsSsl());
+ log::info("ssl support: {}", QSslSocket::supportsSsl());
#else
- qDebug("non-ssl build");
+ log::info("non-ssl build");
#endif
- {
- env::Environment env;
-
- qDebug().nospace().noquote()
- << "windows: " << env.windowsInfo().toString();
-
- if (env.windowsInfo().compatibilityMode()) {
- qWarning() << "MO seems to be running in compatibility mode";
- }
-
- qDebug().nospace().noquote() << "security products:";
- for (const auto& sp : env.securityProducts()) {
- qDebug().nospace().noquote() << " . " << sp.toString();
- }
-
- qDebug() << "modules loaded in process:";
- for (const auto& m : env.loadedModules()) {
- qDebug().nospace().noquote() << " . " << m.toString();
- }
- }
+ dumpEnvironment();
QString dataPath = application.property("dataPath").toString();
qDebug("data path: %s", qUtf8Printable(dataPath));
@@ -795,18 +796,19 @@ void qtLogCallback(
}
}
-void initLogging(const QString& logFile)
+void initLogging()
{
LogModel::create();
- log::init(
- true, MOBase::log::File::rotating(logFile.toStdWString(), 5*1024*1024, 5),
- MOBase::log::Debug, "%^[%m-%d %H:%M:%S.%e %L] %v%$",
+ log::createDefault(MOBase::log::Debug, "%^[%m-%d %H:%M:%S.%e %L] %v%$");
+
+ log::getDefault().setCallback(
[](log::Entry e){ LogModel::instance().add(e); });
qInstallMessageHandler(qtLogCallback);
}
+
int main(int argc, char *argv[])
{
// handle --crashdump first
@@ -820,6 +822,8 @@ int main(int argc, char *argv[])
}
}
+ initLogging();
+
//Make sure the configured temp folder exists
QDir tempDir = QDir::temp();
if (!tempDir.exists())
@@ -882,7 +886,11 @@ int main(int argc, char *argv[])
// initialize dump collection only after "dataPath" since the crashes are stored under it
prevUnhandledExceptionFilter = SetUnhandledExceptionFilter(MyUnhandledExceptionFilter);
- initLogging(qApp->property("dataPath").toString() + "/logs/mo_interface.log");
+ const auto logFile =
+ qApp->property("dataPath").toString() + "/logs/mo_interface.log";
+
+ log::getDefault().setFile(MOBase::log::File::rotating(
+ logFile.toStdWString(), 5*1024*1024, 5));
QString splash = dataPath + "/splash.png";
if (!QFile::exists(dataPath + "/splash.png")) {