introduce "Traffic" and "Debug" categories and change command line parsing to allow override -p

This commit is contained in:
Michael Zanetti 2017-09-27 11:20:52 +02:00
parent 43eba94b87
commit 949583ed93
9 changed files with 61 additions and 37 deletions

View File

@ -118,7 +118,7 @@ quint16 AWSConnector::publish(const QString &topic, const QVariantMap &message)
uint16_t packetId = 0;
ResponseCode res = m_client->PublishAsync(Utf8String::Create(fullTopic.toStdString()), false, false, mqtt::QoS::QOS1, jsonDoc.toJson().toStdString(), &publishCallback, packetId);
qCDebug(dcAWS()) << "publish call queued with status:" << QString::fromStdString(ResponseHelper::ToString(res)) << packetId << "for topic" << topic << jsonDoc.toJson();
qCDebug(dcAWSTraffic()) << "publish call queued with status:" << QString::fromStdString(ResponseHelper::ToString(res)) << packetId << "for topic" << topic << jsonDoc.toJson();
s_requestMap.insert(packetId, this);
return packetId;
}
@ -163,14 +163,14 @@ void AWSConnector::doSubscribe(const QStringList &topics)
{
util::Vector<std::shared_ptr<mqtt::Subscription>> subscription_list;
foreach (const QString &topic, topics) {
qCDebug(dcAWS()) << "topic to subscribe is" << topic << "is valid topic:" << Subscription::IsValidTopicName(topic.toStdString());
qCDebug(dcAWSTraffic()) << "topic to subscribe is" << topic << "is valid topic:" << Subscription::IsValidTopicName(topic.toStdString());
auto subscription = mqtt::Subscription::Create(Utf8String::Create(topic.toStdString()), mqtt::QoS::QOS1, &onSubscriptionReceivedCallback, std::shared_ptr<SubscriptionHandlerContextData>(this));
subscription_list.push_back(subscription);
}
uint16_t packetId;
ResponseCode res = m_client->SubscribeAsync(subscription_list, subscribeCallback, packetId);
qCDebug(dcAWS()) << "subscribe call queued with status:" << QString::fromStdString(ResponseHelper::ToString(res)) << packetId;
qCDebug(dcAWSTraffic()) << "subscribe call queued with status:" << QString::fromStdString(ResponseHelper::ToString(res)) << packetId;
s_requestMap.insert(packetId, this);
}
@ -184,7 +184,7 @@ void AWSConnector::publishCallback(uint16_t actionId, ResponseCode rc)
switch (rc) {
case ResponseCode::SUCCESS:
qCDebug(dcAWS()) << "Successfully published" << actionId;
qCDebug(dcAWSTraffic()) << "Successfully published" << actionId;
break;
default:
qCDebug(dcAWS())<< "Error publishing data to AWS:" << QString::fromStdString(ResponseHelper::ToString(rc));

View File

@ -310,7 +310,9 @@ void JsonRPCServer::sendResponse(TransportInterface *interface, const QUuid &cli
response.insert("status", "success");
response.insert("params", params);
interface->sendData(clientId, QJsonDocument::fromVariant(response).toJson(QJsonDocument::Compact));
QByteArray data = QJsonDocument::fromVariant(response).toJson(QJsonDocument::Compact);
qCDebug(dcJsonRpcTraffic()) << "Sending data:" << data;
interface->sendData(clientId, data);
}
/*! Send a JSON error response to the client with the given \a clientId,
@ -323,7 +325,9 @@ void JsonRPCServer::sendErrorResponse(TransportInterface *interface, const QUuid
errorResponse.insert("status", "error");
errorResponse.insert("error", error);
interface->sendData(clientId, QJsonDocument::fromVariant(errorResponse).toJson(QJsonDocument::Compact));
QByteArray data = QJsonDocument::fromVariant(errorResponse).toJson(QJsonDocument::Compact);
qCDebug(dcJsonRpcTraffic()) << "Sending data:" << data;
interface->sendData(clientId, data);
}
void JsonRPCServer::sendUnauthorizedResponse(TransportInterface *interface, const QUuid &clientId, int commandId, const QString &error)
@ -333,7 +337,9 @@ void JsonRPCServer::sendUnauthorizedResponse(TransportInterface *interface, cons
errorResponse.insert("status", "unauthorized");
errorResponse.insert("error", error);
interface->sendData(clientId, QJsonDocument::fromVariant(errorResponse).toJson(QJsonDocument::Compact));
QByteArray data = QJsonDocument::fromVariant(errorResponse).toJson(QJsonDocument::Compact);
qCDebug(dcJsonRpcTraffic()) << "Sending data:" << data;
interface->sendData(clientId, data);
}
QVariantMap JsonRPCServer::createWelcomeMessage(TransportInterface *interface) const
@ -368,6 +374,8 @@ void JsonRPCServer::setup()
void JsonRPCServer::processData(const QUuid &clientId, const QByteArray &data)
{
qCDebug(dcJsonRpcTraffic()) << "Incoming data:" << data;
TransportInterface *interface = qobject_cast<TransportInterface *>(sender());
QJsonParseError error;
QJsonDocument jsonDoc = QJsonDocument::fromJson(data, &error);

View File

@ -335,7 +335,7 @@ QList<Rule> RuleEngine::evaluateEvent(const Event &event)
{
Device *device = GuhCore::instance()->deviceManager()->findConfiguredDevice(event.deviceId());
qCDebug(dcRuleEngine) << "Evaluate event:" << event << device->name() << event.eventTypeId();
qCDebug(dcRuleEngineDebug) << "Evaluate event:" << event << device->name() << event.eventTypeId();
QList<Rule> rules;
foreach (const RuleId &id, ruleIds()) {

View File

@ -91,7 +91,7 @@ void WebSocketServer::sendData(const QUuid &clientId, const QByteArray &data)
QWebSocket *client = 0;
client = m_clientList.value(clientId);
if (client) {
qCDebug(dcWebSocketServer()) << "Sending data to client" << data;
qCDebug(dcWebSocketServerTraffic()) << "Sending data to client" << data;
client->sendTextMessage(data + '\n');
}
}
@ -146,13 +146,13 @@ void WebSocketServer::onClientDisconnected()
void WebSocketServer::onBinaryMessageReceived(const QByteArray &data)
{
QWebSocket *client = qobject_cast<QWebSocket *>(sender());
qCDebug(dcWebSocketServer) << "Binary message from" << client->peerAddress().toString() << ":" << data;
qCDebug(dcWebSocketServerTraffic()) << "Binary message from" << client->peerAddress().toString() << ":" << data;
}
void WebSocketServer::onTextMessageReceived(const QString &message)
{
QWebSocket *client = qobject_cast<QWebSocket *>(sender());
qCDebug(dcWebSocketServer) << "Text message from" << client->peerAddress().toString() << ":" << message;
qCDebug(dcWebSocketServerTraffic()) << "Text message from" << client->peerAddress().toString() << ":" << message;
emit dataAvailable(m_clientList.key(client), message.toUtf8());
}

View File

@ -26,13 +26,17 @@ Q_LOGGING_CATEGORY(dcApplication, "Application")
Q_LOGGING_CATEGORY(dcDeviceManager, "DeviceManager")
Q_LOGGING_CATEGORY(dcTimeManager, "TimeManager")
Q_LOGGING_CATEGORY(dcRuleEngine, "RuleEngine")
Q_LOGGING_CATEGORY(dcRuleEngineDebug, "RuleEngineDebug")
Q_LOGGING_CATEGORY(dcHardware, "Hardware")
Q_LOGGING_CATEGORY(dcConnection, "Connection")
Q_LOGGING_CATEGORY(dcLogEngine, "LogEngine")
Q_LOGGING_CATEGORY(dcTcpServer, "TcpServer")
Q_LOGGING_CATEGORY(dcTcpServerTraffic, "TcpServerTraffic")
Q_LOGGING_CATEGORY(dcWebServer, "WebServer")
Q_LOGGING_CATEGORY(dcWebSocketServer, "WebSocketServer")
Q_LOGGING_CATEGORY(dcWebSocketServerTraffic, "WebSocketServerTraffic")
Q_LOGGING_CATEGORY(dcJsonRpc, "JsonRpc")
Q_LOGGING_CATEGORY(dcJsonRpcTraffic, "JsonRpcTraffic")
Q_LOGGING_CATEGORY(dcRest, "Rest")
Q_LOGGING_CATEGORY(dcOAuth2, "OAuth2")
Q_LOGGING_CATEGORY(dcAvahi, "Avahi")
@ -40,4 +44,6 @@ Q_LOGGING_CATEGORY(dcCloud, "Cloud")
Q_LOGGING_CATEGORY(dcNetworkManager, "NetworkManager")
Q_LOGGING_CATEGORY(dcUserManager, "UserManager")
Q_LOGGING_CATEGORY(dcAWS, "AWS")
Q_LOGGING_CATEGORY(dcAWSTraffic, "AWSTraffic")
Q_LOGGING_CATEGORY(dcJanus, "Janus")
Q_LOGGING_CATEGORY(dcJanusTraffic, "JanusTraffic")

View File

@ -34,13 +34,17 @@ Q_DECLARE_LOGGING_CATEGORY(dcApplication)
Q_DECLARE_LOGGING_CATEGORY(dcDeviceManager)
Q_DECLARE_LOGGING_CATEGORY(dcTimeManager)
Q_DECLARE_LOGGING_CATEGORY(dcRuleEngine)
Q_DECLARE_LOGGING_CATEGORY(dcRuleEngineDebug)
Q_DECLARE_LOGGING_CATEGORY(dcHardware)
Q_DECLARE_LOGGING_CATEGORY(dcConnection)
Q_DECLARE_LOGGING_CATEGORY(dcLogEngine)
Q_DECLARE_LOGGING_CATEGORY(dcTcpServer)
Q_DECLARE_LOGGING_CATEGORY(dcTcpServerTraffic)
Q_DECLARE_LOGGING_CATEGORY(dcWebServer)
Q_DECLARE_LOGGING_CATEGORY(dcWebSocketServer)
Q_DECLARE_LOGGING_CATEGORY(dcWebSocketServerTraffic)
Q_DECLARE_LOGGING_CATEGORY(dcJsonRpc)
Q_DECLARE_LOGGING_CATEGORY(dcJsonRpcTraffic)
Q_DECLARE_LOGGING_CATEGORY(dcRest)
Q_DECLARE_LOGGING_CATEGORY(dcOAuth2)
Q_DECLARE_LOGGING_CATEGORY(dcAvahi)
@ -48,6 +52,8 @@ Q_DECLARE_LOGGING_CATEGORY(dcCloud)
Q_DECLARE_LOGGING_CATEGORY(dcNetworkManager)
Q_DECLARE_LOGGING_CATEGORY(dcUserManager)
Q_DECLARE_LOGGING_CATEGORY(dcAWS)
Q_DECLARE_LOGGING_CATEGORY(dcAWSTraffic)
Q_DECLARE_LOGGING_CATEGORY(dcJanus)
Q_DECLARE_LOGGING_CATEGORY(dcJanusTraffic)
#endif // LOGGINGCATEGORYS_H

View File

@ -112,12 +112,15 @@ int main(int argc, char *argv[])
s_loggingFilters.insert("Warnings", true);
s_loggingFilters.insert("DeviceManager", true);
s_loggingFilters.insert("RuleEngine", true);
s_loggingFilters.insert("RuleEngineDebug", false);
s_loggingFilters.insert("Hardware", false);
s_loggingFilters.insert("Connection", true);
s_loggingFilters.insert("LogEngine", false);
s_loggingFilters.insert("TcpServer", false);
s_loggingFilters.insert("TcpServerTraffic", false);
s_loggingFilters.insert("WebServer", false);
s_loggingFilters.insert("WebSocketServer", false);
s_loggingFilters.insert("WebSocketServerTraffic", false);
s_loggingFilters.insert("JsonRpc", false);
s_loggingFilters.insert("Rest", false);
s_loggingFilters.insert("OAuth2", false);
@ -128,7 +131,8 @@ int main(int argc, char *argv[])
s_loggingFilters.insert("NetworkManager", true);
s_loggingFilters.insert("UserManager", true);
s_loggingFilters.insert("AWS", false);
s_loggingFilters.insert("Janus", false);
s_loggingFilters.insert("AWSTraffic", false);
s_loggingFilters.insert("JanusTraffic", false);
QHash<QString, bool> loggingFiltersPlugins;
foreach (const QJsonObject &pluginMetadata, DeviceManager::pluginsMetadata()) {
@ -211,20 +215,20 @@ int main(int argc, char *argv[])
s_loggingFilters.insert(category, false);
// check debug area
if (!parser.isSet(allOption)) {
foreach (QString debugArea, parser.values(debugOption)) {
bool enable = !debugArea.startsWith("No");
debugArea.remove(QRegExp("^No"));
if (s_loggingFilters.contains(debugArea)) {
s_loggingFilters[debugArea] = enable;
} else {
qCWarning(dcApplication) << QCoreApplication::translate("main", "No such debug category:") << debugArea;
}
}
} else {
foreach (const QString &debugArea, s_loggingFilters.keys())
if (parser.isSet(allOption)) {
foreach (const QString &debugArea, s_loggingFilters.keys()) {
s_loggingFilters[debugArea] = true;
}
}
// And allow overriding individual values
foreach (QString debugArea, parser.values(debugOption)) {
bool enable = !debugArea.startsWith("No");
debugArea.remove(QRegExp("^No"));
if (s_loggingFilters.contains(debugArea)) {
s_loggingFilters[debugArea] = enable;
} else {
qCWarning(dcApplication) << QCoreApplication::translate("main", "No such debug category:") << debugArea;
}
}
QLoggingCategory::installFilter(loggingCategoryFilter);

View File

@ -4,7 +4,7 @@
<context>
<name>main</name>
<message>
<location filename="../server/main.cpp" line="152"/>
<location filename="../server/main.cpp" line="156"/>
<source>
guh ( /[guːh]/ ) is an open source IoT (Internet of Things) server,
which allows to control a lot of different devices from many different
@ -23,12 +23,12 @@ Szenen undVerhaltensweisen des Systems festzulegen.
</translation>
</message>
<message>
<location filename="../server/main.cpp" line="164"/>
<location filename="../server/main.cpp" line="168"/>
<source>Run guhd in the foreground, not as daemon.</source>
<translation>Starte guhd im Vordergrund, nicht als Service.</translation>
</message>
<message>
<location filename="../server/main.cpp" line="167"/>
<location filename="../server/main.cpp" line="171"/>
<source>Debug categories to enable. Prefix with &quot;No&quot; to disable. Warnings from all categories will be printed unless explicitly muted with &quot;NoWarnings&quot;.
Categories are:</source>
@ -36,17 +36,17 @@ Categories are:</source>
Es gibt folgende Kategorien:</translation>
</message>
<message>
<location filename="../server/main.cpp" line="184"/>
<location filename="../server/main.cpp" line="188"/>
<source>Enables all debug categories. This parameter overrides all debug category parameters.</source>
<translation>Aktiviere alle Debug-Kategorien. Dieser Parameter überschreibt alle anderen Debug-Kategorien Parameter.</translation>
</message>
<message>
<location filename="../server/main.cpp" line="189"/>
<location filename="../server/main.cpp" line="193"/>
<source>Specify a log file to write to, If this option is not specified, logs will be printed to the standard output.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../server/main.cpp" line="221"/>
<location filename="../server/main.cpp" line="230"/>
<source>No such debug category:</source>
<translation>Diese Debug-Kategorie existiert nicht:</translation>
</message>

View File

@ -4,7 +4,7 @@
<context>
<name>main</name>
<message>
<location filename="../server/main.cpp" line="152"/>
<location filename="../server/main.cpp" line="156"/>
<source>
guh ( /[guːh]/ ) is an open source IoT (Internet of Things) server,
which allows to control a lot of different devices from many different
@ -23,12 +23,12 @@ for your environment.
</translation>
</message>
<message>
<location filename="../server/main.cpp" line="164"/>
<location filename="../server/main.cpp" line="168"/>
<source>Run guhd in the foreground, not as daemon.</source>
<translation>Run guhd in the foreground, not as daemon.</translation>
</message>
<message>
<location filename="../server/main.cpp" line="167"/>
<location filename="../server/main.cpp" line="171"/>
<source>Debug categories to enable. Prefix with &quot;No&quot; to disable. Warnings from all categories will be printed unless explicitly muted with &quot;NoWarnings&quot;.
Categories are:</source>
@ -37,17 +37,17 @@ Categories are:</source>
Categories are:</translation>
</message>
<message>
<location filename="../server/main.cpp" line="184"/>
<location filename="../server/main.cpp" line="188"/>
<source>Enables all debug categories. This parameter overrides all debug category parameters.</source>
<translation>Enables all debug categories. This parameter overrides all debug category parameters.</translation>
</message>
<message>
<location filename="../server/main.cpp" line="189"/>
<location filename="../server/main.cpp" line="193"/>
<source>Specify a log file to write to, If this option is not specified, logs will be printed to the standard output.</source>
<translation type="unfinished"></translation>
</message>
<message>
<location filename="../server/main.cpp" line="221"/>
<location filename="../server/main.cpp" line="230"/>
<source>No such debug category:</source>
<translation>No such debug category:</translation>
</message>