diff --git a/data/config/logging.conf b/data/config/logging.conf
deleted file mode 100644
index be2bf225..00000000
--- a/data/config/logging.conf
+++ /dev/null
@@ -1,2 +0,0 @@
-[Rules]
-*.debug=false
diff --git a/data/debug-interface/debug-interface.qrc b/data/debug-interface/debug-interface.qrc
index 733a0ac7..2c14f6e5 100644
--- a/data/debug-interface/debug-interface.qrc
+++ b/data/debug-interface/debug-interface.qrc
@@ -24,5 +24,7 @@
favicons/apple-touch-icon-76x76.png
favicons/apple-touch-icon-114x114.png
favicons/apple-touch-icon-120x120.png
+ edit-copy.svg
+ delete.svg
diff --git a/data/debug-interface/delete.svg b/data/debug-interface/delete.svg
new file mode 100644
index 00000000..c4f9686c
--- /dev/null
+++ b/data/debug-interface/delete.svg
@@ -0,0 +1,177 @@
+
+
+
+
diff --git a/data/debug-interface/edit-copy.svg b/data/debug-interface/edit-copy.svg
new file mode 100644
index 00000000..299f9e01
--- /dev/null
+++ b/data/debug-interface/edit-copy.svg
@@ -0,0 +1,204 @@
+
+
+
+
diff --git a/data/debug-interface/script.js b/data/debug-interface/script.js
index 65dc28a8..68417699 100644
--- a/data/debug-interface/script.js
+++ b/data/debug-interface/script.js
@@ -67,13 +67,13 @@ function connectWebsocket() {
webSocket = new WebSocket(urlString);
webSocket.onopen = function(openEvent) {
- console.log("WebSocket connected: " + JSON.stringify(openEvent, null, 4));
+ console.log("WebSocket connected");
webSocketConnected = true;
document.getElementById("toggleLogsButton").innerHTML = "Stop logs";
};
webSocket.onclose = function(closeEvent) {
- console.log("WebSocket disconnected: " + JSON.stringify(closeEvent, null, 4));
+ console.log("WebSocket disconnected");
webSocketConnected = false;
document.getElementById("toggleLogsButton").innerHTML = "Start logs";
};
@@ -84,7 +84,6 @@ function connectWebsocket() {
webSocket.onmessage = function (messageEvent) {
var message = messageEvent.data;
- console.log("WebSocket data received: " + message);
document.getElementById("logsTextArea").value += message;
document.getElementById("logsTextArea").scrollTop = document.getElementById("logsTextArea").scrollHeight;
};
@@ -92,7 +91,6 @@ function connectWebsocket() {
} catch (exception) {
console.error(exception);
}
-
}
@@ -104,6 +102,86 @@ function disconnectWebsocket() {
}
+function clearLogsContent() {
+ console.log("Clear live log content");
+ var logTextArea = document.getElementById("logsTextArea")
+ logTextArea.value = "";
+}
+
+
+function copyLogsContent() {
+ console.log("Copy live log content");
+ var logTextArea = document.getElementById("logsTextArea")
+
+ logTextArea.select();
+ logTextArea.setSelectionRange(0, 99999); /*For mobile devices*/
+ document.execCommand("copy");
+
+ console.log("Copied text:");
+ console.log(logTextArea.value);
+
+ /* Clear selection */
+ document.select();
+}
+
+
+function loadLoggingCategorySettings() {
+ // Request report file generation
+ var request = new XMLHttpRequest();
+ request.open("GET", "/debug/logging-categories", true);
+ request.send(null);
+
+ request.onreadystatechange = function() {
+ if (request.readyState == 4) {
+ console.log("Load logging category settings finished", request.status);
+
+ /* Check if the generation went fine */
+ if (request.status != 200) {
+ console.warn("Could not load logging category settings", request.status);
+ return;
+ }
+
+ var responseMap = JSON.parse(request.responseText);
+
+ for (var loggingCategory in responseMap['loggingCategories']) {
+ var loggingCategoryElement = document.getElementById("debug-category-" + loggingCategory)
+ loggingCategoryElement.checked = responseMap['loggingCategories'][loggingCategory]
+ }
+
+ for (var loggingCategory in responseMap['loggingCategoriesPlugins']) {
+ var loggingCategoryElement = document.getElementById("debug-category-" + loggingCategory)
+ loggingCategoryElement.checked = responseMap['loggingCategoriesPlugins'][loggingCategory]
+ }
+ }
+ }
+}
+
+
+function toggleLoggingCategory(categoryName) {
+ var switchElement = document.getElementById("debug-category-" + categoryName)
+ console.log("Toggle logging category", categoryName, switchElement.checked)
+
+ var fileRequestUrl = "/debug/logging-categories?" + categoryName + "=" + (switchElement.checked ? "true" : "false");
+
+ // Request report file generation
+ var request = new XMLHttpRequest();
+ request.open("GET", fileRequestUrl, true);
+ request.send(null);
+
+ request.onreadystatechange = function() {
+ if (request.readyState == 4) {
+ console.log("Set logging category settings finished", request.status);
+
+ /* Check if the generation went fine */
+ if (request.status != 200) {
+ console.warn("Could not set logging category settings", request.status);
+ return;
+ }
+ }
+ }
+}
+
+
/* ========================================================================*/
/* File download / show functions
/* ========================================================================*/
@@ -151,7 +229,7 @@ function pollReportResult() {
/* Check if the generation went fine */
if (reportGenerateRequest.status != 200) {
- console.log("Report generation finished with error.");
+ console.warn("Report generation finished with error.");
clearTimeout(generateReportTimer);
textArea.value = "Something went wrong :(" + reportGenerateRequest.status;
button.disabled = false;
@@ -342,5 +420,6 @@ function tracePathTimerTimeout() {
window.onload = function() {
console.log("Window loading finished.");
document.getElementById("informationTabButton").click();
+ loadLoggingCategorySettings();
};
diff --git a/data/debug-interface/styles.css b/data/debug-interface/styles.css
index 86b041c8..7dfa353b 100644
--- a/data/debug-interface/styles.css
+++ b/data/debug-interface/styles.css
@@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
- * Copyright (C) 2018 Simon Stürz *
+ * Copyright (C) 2018-2019 Simon Stürz *
* *
* This file is part of nymea. *
* *
@@ -39,6 +39,14 @@ h1, h2, h3, h4, h5, h6 {
text-align: center;
}
+table {
+ display: table;
+ border-collapse: colapse;
+ border-color: #efefef;
+ min-height: 100px;
+ width: 100%;
+}
+
th, td {
padding: 3px;
padding-left: 10px;
@@ -52,27 +60,10 @@ hr {
color: #efefef;
}
-table {
- display: table;
- border-collapse: colapse;
- border-color: #efefef;
- min-height: 100px;
- width: 100%;
-}
-
button {
width: 100%;
}
-textarea {
- background-color: #3a4055;
- width: 100%;
- padding: 15px;
- min-height: 100px;
- text-align: left;
- border-radius: 10px;
-}
-
.tab {
overflow: hidden;
background-color: #efefef;
@@ -106,8 +97,18 @@ textarea {
}
@keyframes fadeEffect {
- from {opacity: 0;}
- to {opacity: 1;}
+ from { opacity: 0; }
+ to { opacity: 1; }
+}
+
+textarea {
+ background-color: #3a4055;
+ width: 100%;
+ padding: 15px;
+ min-height: 100px;
+ text-align: left;
+ border-radius: 10px;
+ outline: none;
}
.console-textarea {
@@ -212,8 +213,12 @@ textarea {
border-radius: 10px;
opacity: 0.8;
transition: 0.3s;
+ cursor: pointer;
+ outline: none;
}
+button::-moz-focus-inner { border: 0; }
+
.button:hover {
opacity: 1
}
@@ -224,8 +229,136 @@ textarea {
color: #676767;
}
+.log-buttons {
+ display: -webkit-flex; /* Safari */
+ display: flex;
+ flex-flow: row nowrap;
+}
+
+.log-buttons button {
+ display: -webkit-flex; /* Safari */
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ margin: 10px;
+ width: auto;
+}
+
+.tool-image {
+ width: 25px;
+ height: 25px;
+}
+
+#toggleLogsButton {
+ flex-grow: 1;
+}
+
+#copyLogsButton {
+ width: 20px;
+}
+
+#clearLogsButton {
+ width: 20px;
+}
+
+.categories-area {
+ display: -webkit-flex;
+ display: flex;
+ flex-flow: row wrap;
+}
+
+.debug-category {
+ display: -webkit-flex;
+ display: flex;
+ flex-flow: row nowrap;
+ justify-content: center;
+ align-items: center;
+ margin-top: 10px;
+ width: 33%;
+}
+
+.debug-category p {
+ margin: 10px;
+ text-align: right;
+ flex-grow: 1;
+}
+
+/* The switch - the box around the slider */
+.switch {
+ position: relative;
+ display: inline-block;
+ width: 60px;
+ height: 34px;
+}
+
+/* Hide default HTML checkbox */
+.switch input {
+ opacity: 0;
+ width: 0;
+ height: 0;
+}
+
+.switch {
+ position: relative;
+ display: inline-block;
+ width: 60px;
+ height: 34px;
+}
+
+.switch input {
+ opacity: 0;
+ width: 0;
+ height: 0;
+}
+
+.slider {
+ position: absolute;
+ cursor: pointer;
+ top: 0;
+ left: 0;
+ right: 0;
+ bottom: 0;
+ background-color: #ccc;
+ -webkit-transition: .4s;
+ transition: .4s;
+}
+
+.slider:before {
+ position: absolute;
+ content: "";
+ height: 26px;
+ width: 26px;
+ left: 4px;
+ bottom: 4px;
+ background-color: white;
+ -webkit-transition: .4s;
+ transition: .4s;
+}
+
+input:checked + .slider {
+ background-color: #57baae;
+}
+
+input:focus + .slider {
+ box-shadow: 0 0 1px #57baae;
+}
+
+input:checked + .slider:before {
+ -webkit-transform: translateX(26px);
+ -ms-transform: translateX(26px);
+ transform: translateX(26px);
+}
+
+.slider.round {
+ border-radius: 34px;
+}
+
+.slider.round:before {
+ border-radius: 50%;
+}
+
.container {
- min-height:100%;
+ min-height: 100%;
position:relative;
}
diff --git a/data/systemd/nymead.service b/data/systemd/nymead.service
index 05f30e33..184b1de3 100644
--- a/data/systemd/nymead.service
+++ b/data/systemd/nymead.service
@@ -5,8 +5,7 @@ After=network.target
Wants=network-online.target
[Service]
-Environment=QT_LOGGING_CONF=/etc/nymea/logging.conf
-ExecStart=/usr/bin/nymead -n --print-all
+ExecStart=/usr/bin/nymead -n
StandardOutput=journal
StandardError=journal
Restart=on-failure
diff --git a/debian/nymead.install.in b/debian/nymead.install.in
index e8d5fca0..672a4bd3 100644
--- a/debian/nymead.install.in
+++ b/debian/nymead.install.in
@@ -5,4 +5,3 @@ usr/lib/@DEB_HOST_MULTIARCH@/libnymea-core.so.1.0.0
data/systemd/nymead.service /lib/systemd/system/
data/logrotate/nymead /etc/logrotate.d/
data/dbus-1/io.guh.nymead.conf /etc/dbus-1/system.d/
-data/config/logging.conf /etc/nymea/
diff --git a/libnymea-core/debugserverhandler.cpp b/libnymea-core/debugserverhandler.cpp
index 8e883018..f92e8aac 100644
--- a/libnymea-core/debugserverhandler.cpp
+++ b/libnymea-core/debugserverhandler.cpp
@@ -1,6 +1,6 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* *
- * Copyright (C) 2018 Simon Stürz *
+ * Copyright (C) 2018-2019 Simon Stürz *
* *
* This file is part of nymea. *
* *
@@ -379,6 +379,60 @@ HttpReply *DebugServerHandler::processDebugRequest(const QString &requestPath, c
return m_tracePathReply;
}
+ if (requestPath.startsWith("/debug/logging-categories")) {
+
+ if (requestQuery.isEmpty()) {
+ // Return the list of debug category settings
+ NymeaSettings settings(NymeaSettings::SettingsRoleGlobal);
+ settings.beginGroup("LoggingRules");
+
+ qCDebug(dcDebugServer()) << "Request logging categories list";
+ QVariantMap dataMap;
+ QVariantMap loggingCategories;
+ foreach (const QString &loggingCategory, NymeaCore::loggingFilters()) {
+ loggingCategories.insert(loggingCategory, settings.value(QString("%1.debug").arg(loggingCategory), false).toBool());
+ }
+ dataMap.insert("loggingCategories", loggingCategories);
+ QVariantMap loggingCategoriesPlugins;
+ foreach (const QString &loggingCategory, NymeaCore::loggingFiltersPlugins()) {
+ loggingCategoriesPlugins.insert(loggingCategory, settings.value(QString("%1.debug").arg(loggingCategory), false).toBool());
+ }
+ dataMap.insert("loggingCategoriesPlugins", loggingCategoriesPlugins);
+
+ settings.endGroup();
+
+ HttpReply *reply = RestResource::createSuccessReply();
+ reply->setPayload(QJsonDocument::fromVariant(dataMap).toJson(QJsonDocument::Indented));
+ return reply;
+ } else {
+ NymeaSettings settings(NymeaSettings::SettingsRoleGlobal);
+ settings.beginGroup("LoggingRules");
+ for (int i = 0; i < requestQuery.queryItems().count(); i++) {
+ QString category = requestQuery.queryItems().at(i).first;
+ if (!NymeaCore::loggingFilters().contains(category) && !NymeaCore::loggingFiltersPlugins().contains(category)) {
+ qCWarning(dcDebugServer()) << "Invalid logging category in request query" << requestQuery.toString() << category;
+ continue;
+ }
+
+ bool enabled = QVariant(requestQuery.queryItems().at(i).second).toBool();
+ qCDebug(dcDebugServer()) << "Logging category" << category << (enabled ? "enabled" : "disabled");
+ settings.setValue(QString("%1.debug").arg(category), (enabled ? "true" : "false"));
+ }
+
+ // Update logging filter rules according to the nw settings
+ QStringList loggingRules;
+ loggingRules << "*.debug=false";
+ // Load the rules from nymead.conf file and append them to the rules
+ foreach (const QString &category, settings.childKeys()) {
+ loggingRules << QString("%1=%2").arg(category).arg(settings.value(category, "false").toString());
+ }
+ settings.endGroup();
+ QLoggingCategory::setFilterRules(loggingRules.join('\n'));
+
+ return RestResource::createSuccessReply();
+ }
+ }
+
if (requestPath.startsWith("/debug/report")) {
// The client can poll this url in order to get information about the current report generating process.
@@ -562,6 +616,7 @@ void DebugServerHandler::onWebsocketClientConnected()
if (s_websocketClients.isEmpty()) {
qCDebug(dcDebugServer()) << "Install debug message handler for live logs.";
+ //QLoggingCategory::setFilterRules("*.debug=true");
s_oldLogMessageHandler = qInstallMessageHandler(&logMessageHandler);
}
@@ -846,7 +901,6 @@ QByteArray DebugServerHandler::createDebugXmlDocument()
writer.writeStartElement("div");
writer.writeAttribute("class", "body");
-
// ---------------------------------------------------------------------------
writer.writeStartElement("div");
writer.writeAttribute("class", "tabcontent");
@@ -1670,6 +1724,9 @@ QByteArray DebugServerHandler::createDebugXmlDocument()
writer.writeTextElement("p", tr("This section allows you to see the live logs of the nymea server."));
+ writer.writeStartElement("div");
+ writer.writeAttribute("class", "log-buttons");
+
// Toggle log button
writer.writeStartElement("button");
writer.writeAttribute("class", "button");
@@ -1680,6 +1737,31 @@ QByteArray DebugServerHandler::createDebugXmlDocument()
writer.writeCharacters(tr("Start logs"));
writer.writeEndElement(); // button
+ // Copy log content button
+ writer.writeStartElement("button");
+ writer.writeAttribute("class", "button");
+ writer.writeAttribute("type", "button");
+ writer.writeAttribute("id", "copyLogsButton");
+ writer.writeAttribute("onClick", "copyLogsContent()");
+ writer.writeEmptyElement("img");
+ writer.writeAttribute("class", "tool-image");
+ writer.writeAttribute("src", "/debug/edit-copy.svg");
+ writer.writeEndElement(); // button
+
+ // Copy log content button
+ writer.writeStartElement("button");
+ writer.writeAttribute("class", "button");
+ writer.writeAttribute("type", "button");
+ writer.writeAttribute("id", "clearLogsButton");
+ writer.writeAttribute("onClick", "clearLogsContent()");
+ writer.writeEmptyElement("img");
+ writer.writeAttribute("class", "tool-image");
+ writer.writeAttribute("src", "/debug/delete.svg");
+ writer.writeEndElement(); // button
+
+ writer.writeEndElement(); // div log-buttons
+
+
// Logs output
writer.writeStartElement("textarea");
writer.writeAttribute("class", "console-textarea");
@@ -1689,6 +1771,69 @@ QByteArray DebugServerHandler::createDebugXmlDocument()
writer.writeCharacters("");
writer.writeEndElement(); // textarea
+ writer.writeEmptyElement("hr");
+ //: The network section of the debug interface
+ writer.writeTextElement("h2", tr("Logging filters"));
+ writer.writeEmptyElement("hr");
+
+ writer.writeStartElement("div");
+ writer.writeAttribute("class", "categories-area");
+
+ QStringList loggingCategories = NymeaCore::loggingFilters();
+ loggingCategories.sort();
+
+ foreach (const QString &loggingCategory, loggingCategories) {
+ writer.writeStartElement("div");
+ writer.writeAttribute("class", "debug-category");
+ writer.writeTextElement("p", loggingCategory);
+ writer.writeStartElement("label");
+ writer.writeAttribute("class", "switch");
+ writer.writeStartElement("input");
+ writer.writeAttribute("id", QString("debug-category-%1").arg(loggingCategory));
+ writer.writeAttribute("type", "checkbox");
+ writer.writeAttribute("onclick", QString("toggleLoggingCategory('%1')").arg(loggingCategory));
+ writer.writeEndElement(); // input
+ writer.writeStartElement("span");
+ writer.writeAttribute("class", "slider round");
+ writer.writeCharacters("");
+ writer.writeEndElement(); // span
+ writer.writeEndElement(); // label
+ writer.writeEndElement(); // div debug-category
+ }
+
+ writer.writeEndElement(); // div categories-area
+
+ writer.writeEmptyElement("hr");
+ //: The network section of the debug interface
+ writer.writeTextElement("h2", tr("Logging filters plugins"));
+ writer.writeEmptyElement("hr");
+
+ writer.writeStartElement("div");
+ writer.writeAttribute("class", "categories-area");
+
+ QStringList loggingCategoriesPlugins = NymeaCore::loggingFiltersPlugins();
+ loggingCategoriesPlugins.sort();
+ foreach (const QString &loggingCategory, loggingCategoriesPlugins) {
+ writer.writeStartElement("div");
+ writer.writeAttribute("class", "debug-category");
+ writer.writeTextElement("p", loggingCategory);
+ writer.writeStartElement("label");
+ writer.writeAttribute("class", "switch");
+ writer.writeStartElement("input");
+ writer.writeAttribute("id", QString("debug-category-%1").arg(loggingCategory));
+ writer.writeAttribute("type", "checkbox");
+ writer.writeAttribute("onclick", QString("toggleLoggingCategory('%1')").arg(loggingCategory));
+ writer.writeEndElement(); // input
+ writer.writeStartElement("span");
+ writer.writeAttribute("class", "slider round");
+ writer.writeCharacters("");
+ writer.writeEndElement(); // span
+ writer.writeEndElement(); // label
+ writer.writeEndElement(); // div debug-category
+ }
+
+ writer.writeEndElement(); // div categories-area
+
writer.writeEndElement(); // logs-section
writer.writeEndElement(); // div body
diff --git a/libnymea-core/nymeacore.cpp b/libnymea-core/nymeacore.cpp
index a2120758..f4650d72 100644
--- a/libnymea-core/nymeacore.cpp
+++ b/libnymea-core/nymeacore.cpp
@@ -640,6 +640,65 @@ QStringList NymeaCore::getAvailableLanguages()
return availableLanguages;
}
+/*! Returns the list of logging categories from the core and the libnymea. */
+QStringList NymeaCore::loggingFilters()
+{
+ QStringList loggingFilters = {
+ "Warnings",
+ "Application",
+ "System",
+ "Platform",
+ "PlatformUpdate",
+ "PlatformZeroConf",
+ "Device",
+ "DeviceManager",
+ "RuleEngine",
+ "RuleEngineDebug",
+ "Hardware",
+ "Bluetooth",
+ "LogEngine",
+ "ServerManager",
+ "TcpServer",
+ "TcpServerTraffic",
+ "WebServer",
+ "WebServerTraffic",
+ "DebugServer",
+ "WebSocketServer",
+ "WebSocketServerTraffic",
+ "JsonRpc",
+ "JsonRpcTraffic",
+ "Rest",
+ "OAuth2",
+ "TimeManager",
+ "Coap",
+ "Avahi",
+ "AvahiDebug",
+ "UPnP",
+ "Cloud",
+ "CloudTraffic",
+ "NetworkManager",
+ "UserManager",
+ "AWS",
+ "AWSTraffic",
+ "BluetoothServer",
+ "BluetoothServerTraffic",
+ "Mqtt",
+ "Translations"
+ };
+
+ return loggingFilters;
+}
+
+QStringList NymeaCore::loggingFiltersPlugins()
+{
+ QStringList loggingFiltersPlugins;
+ foreach (const QJsonObject &pluginMetadata, DeviceManagerImplementation::pluginsMetadata()) {
+ QString pluginName = pluginMetadata.value("name").toString();
+ loggingFiltersPlugins << pluginName.left(1).toUpper() + pluginName.mid(1);
+ }
+ return loggingFiltersPlugins;
+}
+
/*! Returns a pointer to the \l{BluetoothServer} instance owned by NymeaCore. */
BluetoothServer *NymeaCore::bluetoothServer() const
{
diff --git a/libnymea-core/nymeacore.h b/libnymea-core/nymeacore.h
index 52946ed9..fe54ca20 100644
--- a/libnymea-core/nymeacore.h
+++ b/libnymea-core/nymeacore.h
@@ -96,6 +96,8 @@ public:
Platform *platform() const;
static QStringList getAvailableLanguages();
+ static QStringList loggingFilters();
+ static QStringList loggingFiltersPlugins();
signals:
void initialized();
diff --git a/server/main.cpp b/server/main.cpp
index b8a6d054..ce69a08d 100644
--- a/server/main.cpp
+++ b/server/main.cpp
@@ -97,55 +97,9 @@ int main(int argc, char *argv[])
application.setApplicationName("nymead");
application.setApplicationVersion(NYMEA_VERSION_STRING);
- // logging filers for core and libnymea
- QStringList loggingFilters = {
- "Warnings",
- "Application",
- "System",
- "Platform",
- "PlatformUpdate",
- "PlatformZeroConf",
- "Device",
- "DeviceManager",
- "RuleEngine",
- "RuleEngineDebug",
- "Hardware",
- "Bluetooth",
- "LogEngine",
- "ServerManager",
- "TcpServer",
- "TcpServerTraffic",
- "WebServer",
- "WebServerTraffic",
- "DebugServer",
- "WebSocketServer",
- "WebSocketServerTraffic",
- "JsonRpc",
- "JsonRpcTraffic",
- "Rest",
- "OAuth2",
- "TimeManager",
- "Coap",
- "Avahi",
- "AvahiDebug",
- "UPnP",
- "Cloud",
- "CloudTraffic",
- "NetworkManager",
- "UserManager",
- "AWS",
- "AWSTraffic",
- "BluetoothServer",
- "BluetoothServerTraffic",
- "Mqtt",
- "Translations"
- };
-
- QStringList loggingFiltersPlugins;
- foreach (const QJsonObject &pluginMetadata, DeviceManagerImplementation::pluginsMetadata()) {
- QString pluginName = pluginMetadata.value("name").toString();
- loggingFiltersPlugins << pluginName.left(1).toUpper() + pluginName.mid(1);
- }
+ // Logging filers for core + libnymea and plugins
+ QStringList loggingFilters = NymeaCore::loggingFilters();
+ QStringList loggingFiltersPlugins = NymeaCore::loggingFiltersPlugins();
// Translator for the server application
QTranslator translator;
@@ -217,29 +171,54 @@ int main(int argc, char *argv[])
}
}
- QStringList filterRules;
+
+ /* The logging rules will be evaluated sequentially
+ * 1. All debug categories off
+ * 2. Enable all debug categories if requested from command line (-p)
+ * 3. The stored categories from the nymead.conf will be appended
+ * 4. Add the individual command line params will be added (-d)
+ * 5. QT_LOGGING_CONF
+ * 6. QT_LOGGING_RULES
+ *
+ * The final filter rules will be set.
+ */
+
+ // 1. All debug categories off
+ QStringList loggingRules;
+ loggingRules << "*.debug=false";
+
+ // 2. Enable all debug categories making sense if requested from command line (-p)
if (parser.isSet(allOption)) {
- filterRules << "*.debug=true";
- filterRules << "*Traffic.debug=false";
- filterRules << "*Debug.debug=false";
- } else {
- filterRules << "*.debug=false";
+ loggingRules << "*.debug=true";
+ loggingRules << "*Traffic.debug=false";
+ loggingRules << "*Debug.debug=false";
}
- // And allow overriding individual values
+ // 3. The stored categories from the nymead.conf will be appended
+ NymeaSettings nymeaSettings(NymeaSettings::SettingsRoleGlobal);
+ nymeaSettings.beginGroup("LoggingRules");
+ foreach (const QString &category, nymeaSettings.childKeys()) {
+ loggingRules << QString("%1=%2").arg(category).arg(nymeaSettings.value(category, "false").toString());
+ }
+ nymeaSettings.endGroup();
+
+ // 4. Add the individual command line params will be added (-d)
foreach (QString debugArea, parser.values(debugOption)) {
bool enable = !debugArea.startsWith("No");
bool isWarning = debugArea.endsWith("Warnings");
debugArea.remove(QRegExp("^No"));
debugArea.remove(QRegExp("Warnings$"));
if (loggingFilters.contains(debugArea) || loggingFiltersPlugins.contains(debugArea)) {
- filterRules.append(QString("%1.%2=%3").arg(debugArea).arg(isWarning ? "warning" : "debug").arg(enable ? "true": "false"));
+ loggingRules.append(QString("%1.%2=%3").arg(debugArea).arg(isWarning ? "warning" : "debug").arg(enable ? "true": "false"));
} else {
qCWarning(dcApplication) << QCoreApplication::translate("nymea", "No such debug category:") << debugArea;
}
}
- QLoggingCategory::setFilterRules(filterRules.join('\n'));
+ // Finally set the rules for the logging
+ QLoggingCategory::setFilterRules(loggingRules.join('\n'));
+
+ // Parse DBus option
if (parser.isSet(dbusOption)) {
NymeaDBusService::setBusType(QDBusConnection::SessionBus);
}
@@ -254,13 +233,13 @@ int main(int argc, char *argv[])
fprintf(stdout, "Could not create nymea settings directory %s", qPrintable(NymeaSettings::settingsPath()));
exit(EXIT_FAILURE);
}
- qCInfo(dcApplication) << "=====================================";
- qCInfo(dcApplication) << "nymead" << NYMEA_VERSION_STRING << "started with user ID" << userId;
- qCInfo(dcApplication) << "=====================================";
+ qCInfo(dcApplication()) << "=====================================";
+ qCInfo(dcApplication()) << "nymead" << NYMEA_VERSION_STRING << "started with user ID" << userId;
+ qCInfo(dcApplication()) << "=====================================";
} else {
- qCInfo(dcApplication) << "=====================================";
- qCInfo(dcApplication) << "nymead" << NYMEA_VERSION_STRING << "started as root.";
- qCInfo(dcApplication) << "=====================================";
+ qCInfo(dcApplication()) << "=====================================";
+ qCInfo(dcApplication()) << "nymead" << NYMEA_VERSION_STRING << "started as root.";
+ qCInfo(dcApplication()) << "=====================================";
}
// If running in a snappy environment, print out some details about it.