Merge pull request #191 from monich/logging

Take logging categories into use
This commit is contained in:
Slava Monich 2020-11-22 22:42:33 +02:00 committed by GitHub
commit 10af41eb83
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 123 additions and 72 deletions

View file

@ -145,6 +145,7 @@ HEADERS += \
src/chatmodel.h \
src/dbusadaptor.h \
src/dbusinterface.h \
src/debuglog.h \
src/emojisearchworker.h \
src/fernschreiberutils.h \
src/notificationmanager.h \

View file

@ -16,9 +16,9 @@
*/
#include "appsettings.h"
#include <QDebug>
#define LOG(x) qDebug() << "[AppSettings]" << x
#define DEBUG_MODULE AppSettings
#include "debuglog.h"
namespace {
const QString KEY_SEND_BY_ENTER("sendByEnter");

View file

@ -19,9 +19,9 @@
#include "chatlistmodel.h"
#include "fernschreiberutils.h"
#include <QDebug>
#define LOG(x) qDebug() << "[ChatListModel]" << x
#define DEBUG_MODULE ChatListModel
#include "debuglog.h"
namespace {
const QString ID("id");

View file

@ -22,9 +22,9 @@
#include <QListIterator>
#include <QByteArray>
#include <QBitArray>
#include <QDebug>
#define LOG(x) qDebug() << "[ChatModel]" << x
#define DEBUG_MODULE ChatModel
#include "debuglog.h"
namespace {
const QString ID("id");

View file

@ -19,22 +19,22 @@
#include "dbusadaptor.h"
#include <QDebug>
#define DEBUG_MODULE DBusAdaptor
#include "debuglog.h"
DBusAdaptor::DBusAdaptor(QObject *parent): QDBusAbstractAdaptor(parent)
{
}
void DBusAdaptor::openMessage(const QString &chatId, const QString &messageId)
{
qDebug() << "[DBusAdaptor] Open Message " << chatId << messageId;
LOG("Open Message" << chatId << messageId);
emit pleaseOpenMessage(chatId, messageId);
}
void DBusAdaptor::openUrl(const QStringList &arguments)
{
qDebug() << "[DBusAdaptor] Open Url" << arguments;
LOG("Open Url" << arguments);
if (arguments.length() >= 1) {
emit pleaseOpenUrl(arguments.first());
}

View file

@ -19,27 +19,29 @@
#include "dbusinterface.h"
#define DEBUG_MODULE DBusInterface
#include "debuglog.h"
DBusInterface::DBusInterface(QObject *parent) : QObject(parent)
{
qDebug() << "[DBusInterface] Initializing D-BUS connectivity";
LOG("Initializing D-BUS connectivity");
this->dbusAdaptor = new DBusAdaptor(this);
QDBusConnection sessionBusConnection = QDBusConnection::sessionBus();
if (!sessionBusConnection.isConnected()) {
qDebug() << "[DBusInterface] Error connecting to D-BUS";
WARN("Error connecting to D-BUS");
return;
}
if (!sessionBusConnection.registerObject(PATH_NAME, this)) {
qDebug() << "[DBusInterface] Error registering root object to D-BUS" << sessionBusConnection.lastError().message();
WARN("Error registering root object to D-BUS" << sessionBusConnection.lastError().message());
return;
}
if (!sessionBusConnection.registerService(INTERFACE_NAME)) {
qDebug() << "[DBusInterface] Error registering interface to D-BUS" << sessionBusConnection.lastError().message();
WARN("Error registering interface to D-BUS" << sessionBusConnection.lastError().message());
return;
}
}
DBusAdaptor *DBusInterface::getDBusAdaptor()

45
src/debuglog.h Normal file
View file

@ -0,0 +1,45 @@
/*
Copyright (C) 2020 Slava Monich et al.
This file is part of Fernschreiber.
Fernschreiber is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Fernschreiber is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Fernschreiber. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef FERNSCHREIBER_DEBUG_LOG_H
#define FERNSCHREIBER_DEBUG_LOG_H
#include <QLoggingCategory>
#ifndef DEBUG_MODULE
# define DEBUG_MODULE Debug
#endif
#define LOG_CATEGORY__(x) x##Log
#define LOG_CATEGORY_(x) LOG_CATEGORY__(x)
#define LOG_CATEGORY LOG_CATEGORY_(DEBUG_MODULE)
static const QLoggingCategory LOG_CATEGORY("fernschreiber." QT_STRINGIFY(DEBUG_MODULE));
#define LOG(x) qCDebug(LOG_CATEGORY) << "[" QT_STRINGIFY(DEBUG_MODULE) "]" << x
#define WARN(x) qCWarning(LOG_CATEGORY) << "[" QT_STRINGIFY(DEBUG_MODULE) "]" << x
// No VERBOSE in release build
#ifndef VERBOSE
# if defined (QT_DEBUG) || defined (DEBUG)
# define VERBOSE(x) LOG(x)
# else
# define VERBOSE(x)
# endif
#endif
#endif // FERNSCHREIBER_DEBUG_LOG_H

View file

@ -18,7 +18,8 @@
*/
#include "emojisearchworker.h"
#define LOG(x) qDebug() << "[EmojiSearchWorker]" << x
#define DEBUG_MODULE EmojiSearchWorker
#include "debuglog.h"
EmojiSearchWorker::~EmojiSearchWorker()
{

View file

@ -24,7 +24,6 @@
#include <QSqlQuery>
#include <QSqlError>
#include <QVariantList>
#include <QDebug>
class EmojiSearchWorker : public QThread
{

View file

@ -28,6 +28,7 @@
#include <QQmlContext>
#include <QQmlEngine>
#include <QGuiApplication>
#include <QLoggingCategory>
#include "appsettings.h"
#include "tdlibfile.h"
@ -41,10 +42,20 @@
#include "tgsplugin.h"
#include "fernschreiberutils.h"
// The default filter can be overridden by QT_LOGGING_RULES envinronment variable, e.g.
// QT_LOGGING_RULES="fernschreiber.*=true" harbour-fernschreiber
#if defined (QT_DEBUG) || defined(DEBUG)
# define DEFAULT_LOG_FILTER "fernschreiber.*=true"
#else
# define DEFAULT_LOG_FILTER "fernschreiber.*=false"
#endif
Q_IMPORT_PLUGIN(TgsIOPlugin)
int main(int argc, char *argv[])
{
QLoggingCategory::setFilterRules(DEFAULT_LOG_FILTER);
QScopedPointer<QGuiApplication> app(SailfishApp::application(argc, argv));
QScopedPointer<QQuickView> view(SailfishApp::createView());

View file

@ -21,14 +21,14 @@
#include "fernschreiberutils.h"
#include "chatmodel.h"
#include <sailfishapp.h>
#include <QDebug>
#include <QListIterator>
#include <QUrl>
#include <QDateTime>
#include <QDBusConnection>
#include <QGuiApplication>
#define LOG(x) qDebug() << "[NotificationManager]" << x
#define DEBUG_MODULE NotificationManager
#include "debuglog.h"
namespace {
const QString _TYPE("@type");

View file

@ -1,18 +1,23 @@
#include "processlauncher.h"
#include <QProcess>
#include <QStandardPaths>
#define LOG(x) qDebug() << "[ProcessLauncher]" << x
#define DEBUG_MODULE ProcessLauncher
#include "debuglog.h"
ProcessLauncher::ProcessLauncher(QObject *parent) : QObject(parent)
{
}
bool ProcessLauncher::launchProgram(const QString &program, const QStringList &arguments)
{
QString executablePath = QStandardPaths::findExecutable(program);
if(executablePath == "") {
LOG("[ProcessLauncher] Program " + program + "not found");
const QString executablePath(QStandardPaths::findExecutable(program));
if (executablePath.isEmpty()) {
LOG("Program" << program << "not found");
return false;
}
QProcess *externalProcess = new QProcess(this);
return externalProcess->startDetached(program, arguments);
QProcess *process = new QProcess(this);
connect(process, SIGNAL(finished(int)), process, SLOT(deleteLater()));
return process->startDetached(program, arguments);
}

View file

@ -2,9 +2,6 @@
#define PROCESSLAUNCHER_H
#include <QObject>
#include <QProcess>
#include <QStandardPaths>
#include <QDebug>
class ProcessLauncher : public QObject
{

View file

@ -18,10 +18,10 @@
*/
#include "stickermanager.h"
#include <QDebug>
#include <QListIterator>
#define LOG(x) qDebug() << "[StickerManager]" << x
#define DEBUG_MODULE StickerManager
#include "debuglog.h"
StickerManager::StickerManager(TDLibWrapper *tdLibWrapper, QObject *parent) : QObject(parent)
{

View file

@ -18,9 +18,9 @@
*/
#include "tdlibfile.h"
#include <QDebug>
#define LOG(x) qDebug() << "[TDLibFile]" << x
#define DEBUG_MODULE TDLibFile
#include "debuglog.h"
namespace {
const QString ID("id");

View file

@ -18,13 +18,8 @@
*/
#include "tdlibreceiver.h"
#define LOG(x) qDebug() << "[TDLibReceiver]" << x
#if defined (QT_DEBUG) || defined (DEBUG)
# define VERBOSE(x) LOG(x)
#else
# define VERBOSE(x)
#endif
#define DEBUG_MODULE TDLibReceiver
#include "debuglog.h"
namespace {
const QString ID("id");

View file

@ -19,7 +19,8 @@
#ifndef TDLIBRECEIVER_H
#define TDLIBRECEIVER_H
#include <QDebug>
#include <QHash>
#include <QVariantMap>
#include <QThread>
#include <QJsonDocument>
#include <QJsonObject>

View file

@ -25,19 +25,13 @@
#include <QLocale>
#include <QProcess>
#include <QSysInfo>
#include <QDebug>
#include <QJsonDocument>
#include <QStandardPaths>
#include <QDBusConnection>
#include <QDBusInterface>
#define LOG(x) qDebug() << "[TDLibWrapper]" << x
#if defined (QT_DEBUG) || defined (DEBUG)
# define VERBOSE(x) LOG(x)
#else
# define VERBOSE(x)
#endif
#define DEBUG_MODULE TDLibWrapper
#include "debuglog.h"
namespace {
const QString STATUS("status");
@ -199,7 +193,7 @@ void TDLibWrapper::setAuthenticationPassword(const QString &authenticationPasswo
void TDLibWrapper::registerUser(const QString &firstName, const QString &lastName)
{
qDebug() << "[TDLibWrapper] Register User " << firstName << lastName;
LOG("Register User " << firstName << lastName);
QVariantMap requestObject;
requestObject.insert("@type", "registerUser");
requestObject.insert("first_name", firstName);
@ -890,9 +884,9 @@ void TDLibWrapper::openFileOnDevice(const QString &filePath)
argumentsList.append(filePath);
bool successfullyStarted = QProcess::startDetached("xdg-open", argumentsList);
if (successfullyStarted) {
qDebug() << "Successfully opened file " << filePath;
LOG("Successfully opened file " << filePath);
} else {
qDebug() << "Error opening file " << filePath;
LOG("Error opening file " << filePath);
}
}
@ -903,10 +897,10 @@ void TDLibWrapper::controlScreenSaver(bool enabled)
QDBusInterface dbusInterface("com.nokia.mce", "/com/nokia/mce/request", "com.nokia.mce.request", dbusConnection);
if (enabled) {
qDebug() << "Enabling screensaver";
LOG("Enabling screensaver");
dbusInterface.call("req_display_cancel_blanking_pause");
} else {
qDebug() << "Disabling screensaver";
LOG("Disabling screensaver");
dbusInterface.call("req_display_blanking_pause");
}
}
@ -1178,21 +1172,21 @@ void TDLibWrapper::setLogVerbosityLevel()
void TDLibWrapper::initializeOpenWith()
{
LOG("Initialize open-with");
qDebug() << "Checking standard open URL file...";
QString openUrlFilePath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/open-url.desktop";
LOG("Checking standard open URL file...");
const QString applicationsLocation(QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation));
const QString openUrlFilePath(applicationsLocation + "/open-url.desktop");
if (QFile::exists(openUrlFilePath)) {
qDebug() << "Standard open URL file exists, good!";
LOG("Standard open URL file exists, good!");
} else {
qDebug() << "Copying standard open URL file to " << openUrlFilePath;
LOG("Copying standard open URL file to " << openUrlFilePath);
QFile::copy("/usr/share/applications/open-url.desktop", openUrlFilePath);
QProcess::startDetached("update-desktop-database " + QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation));
QProcess::startDetached("update-desktop-database " + applicationsLocation);
}
QString desktopFilePath = QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation) + "/harbour-fernschreiber-open-url.desktop";
const QString desktopFilePath(applicationsLocation + "/harbour-fernschreiber-open-url.desktop");
QFile desktopFile(desktopFilePath);
if (!desktopFile.exists()) {
qDebug() << "Creating Open-With file at " << desktopFile.fileName();
LOG("Creating Open-With file at " << desktopFile.fileName());
if (desktopFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream fileOut(&desktopFile);
fileOut.setCodec("UTF-8");
@ -1208,7 +1202,7 @@ void TDLibWrapper::initializeOpenWith()
fileOut << QString("Hidden=true;").toUtf8() << "\n";
fileOut.flush();
desktopFile.close();
QProcess::startDetached("update-desktop-database " + QStandardPaths::writableLocation(QStandardPaths::ApplicationsLocation));
QProcess::startDetached("update-desktop-database " + applicationsLocation);
}
}

View file

@ -18,7 +18,6 @@
#include "tgsplugin.h"
#include "rlottie.h"
#include <QDebug>
#include <QSize>
#include <QImage>
#include <QImageIOHandler>
@ -27,8 +26,9 @@
#include <zlib.h>
#define LOG(x) qDebug() << "[TgsIOHandler]" << qPrintable(fileName) << x
#define WARN(x) qWarning() << "[TgsIOHandler]" << qPrintable(fileName) << x
#define DEBUG_MODULE TgsIOHandler
#include "debuglog.h"
#define LOG_(x) LOG(qPrintable(fileName) << x)
class TgsIOHandler : public QImageIOHandler
{
@ -93,7 +93,7 @@ TgsIOHandler::~TgsIOHandler()
if (currentRender.valid()) {
currentRender.get();
}
LOG("Done");
LOG_("Done");
}
TgsIOHandler::ByteArray TgsIOHandler::uncompress()
@ -112,7 +112,7 @@ TgsIOHandler::ByteArray TgsIOHandler::uncompress()
unzip.next_out = (Bytef*)unzipped.data();
unzip.avail_in = zipped.size();
unzip.avail_out = chunk;
LOG("Compressed size" << zipped.size());
LOG_("Compressed size" << zipped.size());
while (unzip.avail_out > 0 && zerr == Z_OK) {
zerr = inflate(&unzip, Z_NO_FLUSH);
if (zerr == Z_OK && unzip.avail_out < chunk) {
@ -124,7 +124,7 @@ TgsIOHandler::ByteArray TgsIOHandler::uncompress()
}
if (zerr == Z_STREAM_END) {
unzipped.resize(unzip.next_out - (Bytef*)unzipped.data());
LOG("Uncompressed size" << unzipped.size());
LOG_("Uncompressed size" << unzipped.size());
} else {
unzipped.clear();
}
@ -146,7 +146,7 @@ bool TgsIOHandler::load()
frameRate = animation->frameRate();
frameCount = (int) animation->totalFrame();
size = QSize(width, height);
LOG(size << frameCount << "frames," << frameRate << "fps");
LOG_(size << frameCount << "frames," << frameRate << "fps");
render(0); // Pre-render first frame
}
}
@ -160,7 +160,7 @@ void TgsIOHandler::finishRendering()
currentRender.get();
prevImage = currentImage;
if (!currentFrame && !firstImage.isNull()) {
LOG("Rendered first frame");
LOG_("Rendered first frame");
firstImage = currentImage;
}
} else {
@ -192,7 +192,7 @@ bool TgsIOHandler::read(QImage* out)
if (currentFrame && currentRender.valid()) {
std::future_status status = currentRender.wait_for(std::chrono::milliseconds(0));
if (status != std::future_status::ready) {
LOG("Skipping frame" << currentFrame);
LOG_("Skipping frame" << currentFrame);
currentFrame = (currentFrame + 1) % frameCount;
*out = prevImage;
return true;