aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAqua-sama <aqua@iserlohn-fortress.net>2019-02-06 21:58:33 +0200
committerAqua-sama <aqua@iserlohn-fortress.net>2019-02-06 21:58:33 +0200
commite3e178e07c58f78eaa7066a64d2e6dd9acd66bd3 (patch)
treed172099b638563118a2df7d313fc96db72dd4889
parentFix all profiles being created off-the-record (diff)
downloadsmolbote-e3e178e07c58f78eaa7066a64d2e6dd9acd66bd3.tar.xz
Use spdlog for logging
-rw-r--r--.gitignore5
-rw-r--r--lib/webprofile/webprofile.cpp1
-rw-r--r--meson.build3
-rw-r--r--src/browser.cpp2
-rw-r--r--src/main.cpp23
-rw-r--r--src/meson.build2
-rw-r--r--src/util.cpp3
-rw-r--r--src/util.h2
-rw-r--r--src/webengine/webpage.cpp5
-rw-r--r--src/webengine/webview.cpp5
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<QWebEngineProfile::HttpCacheType>(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 <spdlog/spdlog.h>
Browser::Browser(int &argc, char *argv[], bool allowSecondary)
: SingleApplication(argc, argv, allowSecondary, SingleApplication::User | SingleApplication::SecondaryNotification | SingleApplication::ExcludeAppVersion)
@@ -118,6 +119,7 @@ QPair<QString, Profile *> Browser::loadProfile(const QString &id, bool isOffTheR
}
profile->setRequestInterceptor(interceptor);
+ spdlog::info("Added profile: {}{}", qUtf8Printable(_id), profile->isOffTheRecord() ? " (otr)" : "");
return QPair<QString, WebProfile *>(_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 <QTranslator>
#include <memory>
#include <plugininterface.h>
-#ifdef _WIN32
-#include <cstdio>
-#include <windows.h>
-#endif
+#include <spdlog/spdlog.h>
#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<CommandLine> cmd = std::make_unique<CommandLine>(argc, argv);
@@ -77,16 +72,14 @@ int main(int argc, char **argv)
for(const QString &path : Util::files(config->value<QString>("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<PluginInterface *>(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 <QDir>
#include <QFileInfo>
#include <QApplication>
+#include <spdlog/spdlog.h>
#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 <QTimer>
#include <QWebEngineFullScreenRequest>
#include <QWebEngineCertificateError>
+#include <spdlog/spdlog.h>
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 = "<html><body><h1>This tab has crashed!</h1>%message%</body></html>";
page.replace(QLatin1String("%message%"), QString("<p>%1<br>Exit code is %2.</p>"
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();