summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Holthuis <jan.holthuis@ruhr-uni-bochum.de>2022-01-11 00:20:01 +0100
committerGitHub <noreply@github.com>2022-01-11 00:20:01 +0100
commit3d606d284de494200ffb67763e4518284afa4c5d (patch)
tree6ef7aefec3da3a299006ba53e0c4d11191ddc21e
parente5a00a7eb87a77e3f0c44098c1968d5e45b99981 (diff)
lp1956819: Show log messages from "js" category on `--controller-debug` (#4612)
* Logging: Show messages from "js" category on `--controller-debug` The JavaScript Console API uses the `js` logging category: > The output is generated using the qCDebug, qCWarning, qCCritical > methods in C++, with a category of "qml" or "js", depending on the > type of file doing the logging. > > Source: > https://doc.qt.io/archives/qt-5.10/qtquick-debugging.html#console-api Hence, the `--controller-debug` command line flag needs to enable logging output for the `js` category, too. Fixes lp1956819: https://bugs.launchpad.net/mixxx/+bug/1956819
-rw-r--r--src/util/logging.cpp19
1 files changed, 15 insertions, 4 deletions
diff --git a/src/util/logging.cpp b/src/util/logging.cpp
index 859b111b2c..49d95445de 100644
--- a/src/util/logging.cpp
+++ b/src/util/logging.cpp
@@ -12,6 +12,7 @@
#include <QString>
#include <QTextStream>
#include <QThread>
+#include <string_view>
#include "util/assert.h"
#include "util/cmdlineargs.h"
@@ -30,14 +31,24 @@ QFile s_logfile;
QLoggingCategory::CategoryFilter oldCategoryFilter = nullptr;
+/// Logging category for messages logged via the JavaScript Console API.
+constexpr std::string_view jsLoggingCategory = {"js"};
+
+/// Logging category prefix for messages logged by the controller system.
+constexpr std::string_view controllerLoggingCategoryPrefix = {"controller."};
+
/// Filters logging categories for the `--controller-debug` command line
/// argument, so that debug messages are enabled for all categories in the
/// `controller` namespace, and disabled for all other categories.
void controllerDebugCategoryFilter(QLoggingCategory* category) {
- // Configure controller.*.input/output category here, otherwise forward to to default filter.
- constexpr char controllerPrefix[] = "controller.";
- const char* categoryName = category->categoryName();
- if (qstrncmp(categoryName, controllerPrefix, sizeof(controllerPrefix) - 1) == 0) {
+ // Configure `js` or `controller.*` categories here, otherwise forward to to default filter.
+ const std::string_view categoryName{category->categoryName()};
+ // TODO: Use `categoryName.starts_with(controllerLoggingCategoryPrefix)` once we switch to C++20.
+ if (categoryName == jsLoggingCategory ||
+ categoryName.substr(0,
+ std::min(categoryName.size(),
+ controllerLoggingCategoryPrefix.size())) ==
+ controllerLoggingCategoryPrefix) {
// If the logging category name starts with `controller.`, show debug messages.
category->setEnabled(QtDebugMsg, true);
} else {