Log directory/device list renewal when event logging enabled

This is useful for debugging to track (unnecessary) renewal of those
lists.
This commit is contained in:
Martchus 2019-07-25 18:27:38 +02:00
parent 205189c34a
commit 7e46096feb
2 changed files with 20 additions and 1 deletions

View File

@ -99,7 +99,7 @@ endif ()
# configure whether events should be logged
option(SYNCTHING_CONNECTION_LOG_SYNCTHING_EVENTS "enables logging event data to stdout (enable only for debugging!)" OFF)
if (SYNCTHING_CONNECTION_LOG_SYNCTHING_EVENTS)
set_property(SOURCE syncthingconnection_requests.cpp
set_property(SOURCE syncthingconnection.cpp syncthingconnection_requests.cpp
APPEND
PROPERTY COMPILE_DEFINITIONS ${META_PROJECT_VARNAME_UPPER}_LOG_SYNCTHING_EVENTS)
message(WARNING "SyncthingConnection class will log event data to stdout")

View File

@ -9,6 +9,11 @@
#include <c++utilities/conversion/stringconversion.h>
#if defined(LIB_SYNCTHING_CONNECTOR_LOG_SYNCTHING_EVENTS) || defined(LIB_SYNCTHING_CONNECTOR_LOG_API_CALLS)
#include <c++utilities/io/ansiescapecodes.h>
#include <iostream>
#endif
#include <QAuthenticator>
#include <QHostAddress>
#include <QJsonArray>
@ -24,6 +29,9 @@
using namespace std;
using namespace CppUtilities;
#if defined(LIB_SYNCTHING_CONNECTOR_LOG_SYNCTHING_EVENTS) || defined(LIB_SYNCTHING_CONNECTOR_LOG_API_CALLS)
using namespace CppUtilities::EscapeCodes;
#endif
namespace Data {
@ -112,6 +120,17 @@ SyncthingConnection::SyncthingConnection(const QString &syncthingUrl, const QByt
#ifdef LIB_SYNCTHING_CONNECTOR_CONNECTION_MOCKED
setupTestData();
#endif
#ifdef LIB_SYNCTHING_CONNECTOR_LOG_SYNCTHING_EVENTS
QObject::connect(this, &SyncthingConnection::newDirs, [] (const auto &dirs) {
std::cerr << Phrases::Info << "Directory list renewed:" << Phrases::End;
std::cerr << displayNames(dirs).join(QStringLiteral(", ")).toStdString() << endl;
});
QObject::connect(this, &SyncthingConnection::newDevices, [] (const auto &devs) {
std::cerr << Phrases::Info << "Device list renewed:" << Phrases::End;
std::cerr << displayNames(devs).join(QStringLiteral(", ")).toStdString() << endl;
});
#endif
}
/*!