From f56a60c4c108a5b192d00a692016ef28984c958d Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Wed, 5 Aug 2020 11:04:18 +0200 Subject: [PATCH] Remove redundant code. --- src/librssguard/core/feeddownloader.cpp | 9 +- src/librssguard/definitions/definitions.h | 2 + src/librssguard/librssguard.pro | 2 - src/librssguard/miscellaneous/application.cpp | 9 +- src/librssguard/miscellaneous/debugging.cpp | 97 ------------------- src/librssguard/miscellaneous/debugging.h | 34 ------- 6 files changed, 8 insertions(+), 145 deletions(-) delete mode 100644 src/librssguard/miscellaneous/debugging.cpp delete mode 100644 src/librssguard/miscellaneous/debugging.h diff --git a/src/librssguard/core/feeddownloader.cpp b/src/librssguard/core/feeddownloader.cpp index 87df9ed78..f76b87ae4 100644 --- a/src/librssguard/core/feeddownloader.cpp +++ b/src/librssguard/core/feeddownloader.cpp @@ -27,7 +27,7 @@ FeedDownloader::~FeedDownloader() { m_mutex->tryLock(); m_mutex->unlock(); delete m_mutex; - qDebug("Destroying FeedDownloader instance."); + qDebugNN << LOGSEC_FEEDDOWNLOADER << "Destroying FeedDownloader instance."; } bool FeedDownloader::isUpdateRunning() const { @@ -39,7 +39,9 @@ void FeedDownloader::updateAvailableFeeds() { auto* cache = dynamic_cast(feed->getParentServiceRoot()); if (cache != nullptr) { - qDebug("Saving cache for feed with DB ID %d and title '%s'.", feed->id(), qPrintable(feed->title())); + qDebugNN << LOGSEC_FEEDDOWNLOADER + << "Saving cache for feed with DB ID '" << feed->id() + << "' and title '" << feed->title() << "'."; cache->saveAllCachedData(false); } } @@ -132,11 +134,10 @@ void FeedDownloader::updateOneFeed(Feed* feed) { QList read_msgs, important_msgs; for (int i = 0; i < msgs.size(); i++) { - tmr.restart(); - Message msg_backup(msgs[i]); // Attach live message object to wrapper. + tmr.restart(); msg_obj.setMessage(&msgs[i]); qDebugNN << "Hooking message took " << tmr.nsecsElapsed() / 1000 << " microseconds."; diff --git a/src/librssguard/definitions/definitions.h b/src/librssguard/definitions/definitions.h index 26d960562..311eaea5b 100755 --- a/src/librssguard/definitions/definitions.h +++ b/src/librssguard/definitions/definitions.h @@ -82,6 +82,8 @@ #define HTTP_HEADERS_AUTHORIZATION "Authorization" #define HTTP_HEADERS_USER_AGENT "User-Agent" +#define LOGSEC_FEEDDOWNLOADER "feed-downloader: " + #define MAX_ZOOM_FACTOR 5.0f #define MIN_ZOOM_FACTOR 0.25f #define DEFAULT_ZOOM_FACTOR 1.0f diff --git a/src/librssguard/librssguard.pro b/src/librssguard/librssguard.pro index 0b6f8930e..7e60d0bf9 100644 --- a/src/librssguard/librssguard.pro +++ b/src/librssguard/librssguard.pro @@ -96,7 +96,6 @@ HEADERS += core/feeddownloader.h \ miscellaneous/databasecleaner.h \ miscellaneous/databasefactory.h \ miscellaneous/databasequeries.h \ - miscellaneous/debugging.h \ miscellaneous/externaltool.h \ miscellaneous/feedreader.h \ miscellaneous/iconfactory.h \ @@ -243,7 +242,6 @@ SOURCES += core/feeddownloader.cpp \ miscellaneous/databasecleaner.cpp \ miscellaneous/databasefactory.cpp \ miscellaneous/databasequeries.cpp \ - miscellaneous/debugging.cpp \ miscellaneous/externaltool.cpp \ miscellaneous/feedreader.cpp \ miscellaneous/iconfactory.cpp \ diff --git a/src/librssguard/miscellaneous/application.cpp b/src/librssguard/miscellaneous/application.cpp index 2713913c8..82d341ca8 100755 --- a/src/librssguard/miscellaneous/application.cpp +++ b/src/librssguard/miscellaneous/application.cpp @@ -10,7 +10,6 @@ #include "gui/feedsview.h" #include "gui/messagebox.h" #include "gui/statusbar.h" -#include "miscellaneous/debugging.h" #include "miscellaneous/feedreader.h" #include "miscellaneous/iconfactory.h" #include "miscellaneous/iofactory.h" @@ -55,8 +54,7 @@ Application::Application(const QString& id, int& argc, char** argv) m_database(new DatabaseFactory(this)), m_downloadManager(nullptr), m_shouldRestart(false) { // Setup debug output system. - qInstallMessageHandler(Debugging::debugHandler); - + qSetMessagePattern(QSL("time=\"%{time process}\" type=\"%{type}\" -> %{message}\n")); determineFirstRuns(); //: Abbreviation of language, e.g. en. @@ -92,11 +90,6 @@ Application::Application(const QString& id, int& argc, char** argv) new RssGuardSchemeHandler(QWebEngineProfile::defaultProfile())); #endif - if (arguments().contains(QL1S("-log"))) { - Debugging::instance()->setTargetFile(IOFactory::getSystemFolder(QStandardPaths::TempLocation) + - QDir::separator() + QL1S("rssguard.log")); - } - m_webFactory->updateProxy(); } diff --git a/src/librssguard/miscellaneous/debugging.cpp b/src/librssguard/miscellaneous/debugging.cpp deleted file mode 100644 index 6487d8dfd..000000000 --- a/src/librssguard/miscellaneous/debugging.cpp +++ /dev/null @@ -1,97 +0,0 @@ -// For license of this file, see /LICENSE.md. - -#include "miscellaneous/debugging.h" - -#include "miscellaneous/application.h" - -#include - -#include -#include -#include -#include - -Q_GLOBAL_STATIC(Debugging, qz_debug_acmanager) - -Debugging * Debugging::instance() { - return qz_debug_acmanager(); -} - -void Debugging::setTargetFile(const QString& targetFile) { - m_targetFile = targetFile; - - if (!m_targetFile.isEmpty()) { - m_targetFileHandle = new QFile(m_targetFile); - m_targetFileHandle->open(QIODevice::WriteOnly | QIODevice::Append); - } -} - -QString Debugging::targetFile() const { - return m_targetFile; -} - -QFile* Debugging::targetFileHandle() { - return m_targetFileHandle; -} - -void Debugging::performLog(const char* message, QtMsgType type, const char* file, const char* function, int line) { - const char* type_string = typeToString(type); - QString date_str = QDateTime::currentDateTimeUtc().toString(QSL("yyyy-MM-dd HH:mm:ss.zzz UTC")); - - if (instance()->targetFile().isEmpty()) { - - // Write to console. - if (file == nullptr || function == nullptr || line < 0) { - fprintf(stderr, "[%s] %s: %s (%s)\n", APP_LOW_NAME, type_string, message, qPrintable(date_str)); - } - else { - fprintf(stderr, "[%s] %s (%s)\n Type: %s\n File: %s (line %d)\n Function: %s\n\n", - APP_LOW_NAME, message, qPrintable(date_str), type_string, file, line, function); - } - } - else { - if (file == nullptr || function == nullptr || line < 0) { - instance()->targetFileHandle()->write(QString("[%1] %2: %3 (%4)\n").arg(APP_LOW_NAME, type_string, - message, qPrintable(date_str)).toUtf8()); - } - else { - instance()->targetFileHandle()->write(QString("[%1] %2 (%3)\n Type: %4\n File: %5 (line %6)\n Function: %7\n\n") - .arg(APP_LOW_NAME, message, qPrintable(date_str), type_string, - file, QString::number(line), function).toUtf8()); - } - - instance()->targetFileHandle()->flush(); - } - - if (type == QtFatalMsg) { - qApp->exit(EXIT_FAILURE); - } -} - -const char* Debugging::typeToString(QtMsgType type) { - switch (type) { - case QtDebugMsg: - return "DEBUG"; - - case QtWarningMsg: - return "WARNING"; - - case QtCriticalMsg: - return "CRITICAL"; - - case QtFatalMsg: - default: - return "FATAL (terminating application)"; - } -} - -Debugging::Debugging() = default; -void Debugging::debugHandler(QtMsgType type, const QMessageLogContext& placement, const QString& message) { -#ifndef QT_NO_DEBUG_OUTPUT - performLog(qPrintable(message), type, placement.file, placement.function, placement.line); -#else - Q_UNUSED(type) - Q_UNUSED(placement) - Q_UNUSED(message) -#endif -} diff --git a/src/librssguard/miscellaneous/debugging.h b/src/librssguard/miscellaneous/debugging.h deleted file mode 100644 index 53d7ccc71..000000000 --- a/src/librssguard/miscellaneous/debugging.h +++ /dev/null @@ -1,34 +0,0 @@ -// For license of this file, see /LICENSE.md. - -#ifndef DEBUGGING_H -#define DEBUGGING_H - -#include - -#include -#include - -class Debugging { - public: - explicit Debugging(); - - // Specifies format of output console messages. - // NOTE: QT_NO_DEBUG_OUTPUT - disables debug outputs completely!!! - static void debugHandler(QtMsgType type, const QMessageLogContext& placement, const QString& message); - static void performLog(const char* message, QtMsgType type, const char* file = nullptr, const char* function = nullptr, int line = -1); - static const char* typeToString(QtMsgType type); - - // Returns pointer to global silent network manager - static Debugging* instance(); - - void setTargetFile(const QString& targetFile); - QString targetFile() const; - - QFile* targetFileHandle(); - - private: - QString m_targetFile; - QFile* m_targetFileHandle{}; -}; - -#endif // DEBUGGING_H