From e3e178e07c58f78eaa7066a64d2e6dd9acd66bd3 Mon Sep 17 00:00:00 2001 From: Aqua-sama Date: Wed, 6 Feb 2019 21:58:33 +0200 Subject: Use spdlog for logging --- src/main.cpp | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 0072b04..dfe58de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -21,10 +21,7 @@ #include #include #include -#ifdef _WIN32 -#include -#include -#endif +#include #include "config.h" #if defined(CONFIG_USEPLASMA) && !defined(PLASMA) @@ -37,12 +34,10 @@ int main(int argc, char **argv) { - // a beautiful hack to be able to write to stdout on Windows -#ifdef _WIN32 - if(AttachConsole(ATTACH_PARENT_PROCESS)) { - freopen("CONOUT$", "w", stdout); - freopen("CONOUT$", "w", stderr); - } + // change log pattern + spdlog::set_pattern("[%^%l%$] [%P:%t] %v"); +#ifdef QT_DEBUG + spdlog::set_level(spdlog::level::debug); // Set global log level to debug #endif const std::unique_ptr cmd = std::make_unique(argc, argv); @@ -77,16 +72,14 @@ int main(int argc, char **argv) for(const QString &path : Util::files(config->value("plugins.path").value())) { auto *loader = new QPluginLoader(path); const bool loaded = loader->load(); -#ifdef QT_DEBUG - qDebug("Loading plugin %s %s", qUtf8Printable(path), loaded ? "[ok]" : "[failed]"); -#endif + spdlog::info("{} plugin {}", loaded ? "Loaded" : "Failed to load", qUtf8Printable(path)); if(loaded) { plugins.append(loader); auto *plugin = qobject_cast(loader->instance()); pluginCommands.unite(plugin->commands()); } else { - qDebug("%s", qUtf8Printable(loader->errorString())); + spdlog::warn("{}", qUtf8Printable(loader->errorString())); delete loader; } } @@ -131,7 +124,7 @@ int main(int argc, char **argv) google_breakpad::ExceptionHandler eh(descriptor, nullptr, CrashHandler::dumpCallback, &ctx, true, -1); #ifdef QT_DEBUG - qDebug("Installed breakpad exception handler (path=%s)", crashpath.c_str()); + spdlog::info("Installed breakpad exception handler (path {})", crashpath); #endif #endif // CONFIG_USEBREAKPAD -- cgit v1.2.1