Remove redundant code.

This commit is contained in:
Martin Rotter 2020-08-05 11:04:18 +02:00
parent 962ba67a55
commit f56a60c4c1
6 changed files with 8 additions and 145 deletions

View File

@ -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<CacheForServiceRoot*>(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<Message> 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.";

View File

@ -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

View File

@ -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 \

View File

@ -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();
}

View File

@ -1,97 +0,0 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#include "miscellaneous/debugging.h"
#include "miscellaneous/application.h"
#include <QDir>
#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <ctime>
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
}

View File

@ -1,34 +0,0 @@
// For license of this file, see <project-root-folder>/LICENSE.md.
#ifndef DEBUGGING_H
#define DEBUGGING_H
#include <QtGlobal>
#include <QFile>
#include <QString>
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