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 --- .gitignore | 5 +---- lib/webprofile/webprofile.cpp | 1 - meson.build | 3 +++ src/browser.cpp | 2 ++ src/main.cpp | 23 ++++++++--------------- src/meson.build | 2 +- src/util.cpp | 3 ++- src/util.h | 2 +- src/webengine/webpage.cpp | 5 ++--- src/webengine/webview.cpp | 5 +---- 10 files changed, 21 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index fd7fd1b..9a8ff3a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,3 @@ -# clion -cmake-build-* -.idea - # kdevelop build* *.kdev4 @@ -9,6 +5,7 @@ build* # qtcreator *.user +subprojects/ lang/*.qm test/plugins.d diff --git a/lib/webprofile/webprofile.cpp b/lib/webprofile/webprofile.cpp index b7747a7..843b78e 100644 --- a/lib/webprofile/webprofile.cpp +++ b/lib/webprofile/webprofile.cpp @@ -116,7 +116,6 @@ void WebProfile::setHttpCacheMaximumSize(int maxSize) void WebProfile::setHttpCacheType(int type) { - qDebug("set httpCacheType to %i", type); QWebEngineProfile::setHttpCacheType(static_cast(type)); emit propertyChanged("httpCacheType", type); } diff --git a/meson.build b/meson.build index be584ac..d4a8bd7 100644 --- a/meson.build +++ b/meson.build @@ -16,6 +16,9 @@ dep_qt5 = dependency('qt5', modules: ['Core', 'Network', 'Widgets', 'WebEngineWi # Boost dep_boost = dependency('boost', modules: ['program_options']) +# spdlog +dep_spdlog = dependency('spdlog', fallback: ['spdlog', 'spdlog_dep'], version: '>=1.3.1') + # Breakpad if get_option('Breakpad').enabled() dep_breakpad = declare_dependency( diff --git a/src/browser.cpp b/src/browser.cpp index 430a7d4..69db6b2 100644 --- a/src/browser.cpp +++ b/src/browser.cpp @@ -37,6 +37,7 @@ #include "urlfilter.h" #include "adblock/adblocklist.h" #include "hostlist/hostlist.h" +#include Browser::Browser(int &argc, char *argv[], bool allowSecondary) : SingleApplication(argc, argv, allowSecondary, SingleApplication::User | SingleApplication::SecondaryNotification | SingleApplication::ExcludeAppVersion) @@ -118,6 +119,7 @@ QPair Browser::loadProfile(const QString &id, bool isOffTheR } profile->setRequestInterceptor(interceptor); + spdlog::info("Added profile: {}{}", qUtf8Printable(_id), profile->isOffTheRecord() ? " (otr)" : ""); return QPair(_id, profile); } 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 diff --git a/src/meson.build b/src/meson.build index ce4e216..6d5a42e 100644 --- a/src/meson.build +++ b/src/meson.build @@ -13,7 +13,7 @@ poi_moc = qt5.preprocess( poi = executable(get_option('poiName'), install: true, cpp_args: ['-DQAPPLICATION_CLASS=QApplication'], - dependencies: [dep_qt5, dep_boost, dep_SingleApplication, dep_genheaders, dep_breakpad, dep_plasma, + dependencies: [dep_qt5, dep_boost, dep_SingleApplication, dep_genheaders, dep_breakpad, dep_plasma, dep_spdlog, dep_about, dep_addressbar, dep_bookmarks, dep_configuration, dep_downloads, dep_urlfilter, dep_webprofile], include_directories: [include], sources: ['main.cpp', 'builtins.cpp', 'crashhandler.cpp', poi_moc, diff --git a/src/util.cpp b/src/util.cpp index adf1f85..cd73d94 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #define ListSeparator QLatin1Literal(";") @@ -61,7 +62,7 @@ QIcon Util::icon(QStyle::StandardPixmap id) { return QIcon::fromTheme("go-home", qApp->style()->standardIcon(id)); default: - qDebug("FIXME: unhandled StandardPixmap %i", id); + spdlog::warn("FIXME: unhandled StandardPixmap {}", id); return qApp->style()->standardIcon(id); } } diff --git a/src/util.h b/src/util.h index 6019366..d96dc19 100644 --- a/src/util.h +++ b/src/util.h @@ -16,7 +16,7 @@ namespace Util { const QStringList files(const QString &location, const QStringList &nameFilters = QStringList()); -QIcon icon(QStyle::StandardPixmap id); +[[nodiscard]] QIcon icon(QStyle::StandardPixmap id); } diff --git a/src/webengine/webpage.cpp b/src/webengine/webpage.cpp index ecbb1b9..15d2322 100644 --- a/src/webengine/webpage.cpp +++ b/src/webengine/webpage.cpp @@ -12,6 +12,7 @@ #include #include #include +#include QString tr_terminationStatus(QWebEnginePage::RenderProcessTerminationStatus status) { @@ -114,9 +115,7 @@ void WebPage::featurePermissionDialog(const QUrl &securityOrigin, QWebEnginePage void WebPage::renderProcessCrashed(QWebEnginePage::RenderProcessTerminationStatus terminationStatus, int exitCode) { if(terminationStatus != QWebEnginePage::NormalTerminationStatus) { -#ifdef QT_DEBUG - qDebug("render process terminated: [%i] %i", terminationStatus, exitCode); -#endif + spdlog::warn("render process terminated: [{}] {}", terminationStatus, exitCode); QString page = "

This tab has crashed!

%message%"; page.replace(QLatin1String("%message%"), QString("

%1
Exit code is %2.

" diff --git a/src/webengine/webview.cpp b/src/webengine/webview.cpp index 5e350eb..5c9ab26 100644 --- a/src/webengine/webview.cpp +++ b/src/webengine/webview.cpp @@ -87,10 +87,7 @@ void WebView::search(const QString &term) WebView *WebView::createWindow(QWebEnginePage::WebWindowType type) { - if(m_parentWindow == nullptr) { - qDebug("WebView::createWindow: parent window not found, returning nullptr"); - return nullptr; - } + Q_CHECK_PTR(m_parentWindow); // parent Window has been found auto index = m_parentWindow->addTab(); -- cgit v1.2.1