diff options
-rw-r--r-- | src/util/logging.cpp | 19 |
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 { |