summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qloggingregistry.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2021-09-20 23:07:52 -0700
committerThiago Macieira <thiago.macieira@intel.com>2021-10-27 12:40:33 -0700
commit806545fcc8d6b3b96a5191a00a31e9a39837189c (patch)
tree10ebd91c2936f4c187f24f7e0f154fffec0ed493 /src/corelib/io/qloggingregistry.cpp
parent0c0892a3e20aa1fa79e3561de9b8e1fa8820f062 (diff)
QLoggingRegistry: add the ability to have environment variable overrides
Quite a lot of our code in Qt predating QLoggingCategory has manual environment variable controls. For compatibility with established documentation and tips-and-tricks out there, we should keep them working when switching to categorized logging. Change-Id: I3eb1bd30e0124f89a052fffd16a6c151d3e9d552 Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@gmx.de> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qloggingregistry.cpp')
-rw-r--r--src/corelib/io/qloggingregistry.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp
index 08818c89d7..1c26e3d1c1 100644
--- a/src/corelib/io/qloggingregistry.cpp
+++ b/src/corelib/io/qloggingregistry.cpp
@@ -371,6 +371,20 @@ void QLoggingRegistry::unregisterCategory(QLoggingCategory *cat)
}
/*!
+ \since 6.3
+ \internal
+
+ Registers the environment variable \a environment as the control variable
+ for enabling debugging by default for category \a categoryName. The
+ category name must start with "qt."
+*/
+void QLoggingRegistry::registerEnvironmentOverrideForCategory(QByteArrayView categoryName,
+ QByteArrayView environment)
+{
+ qtCategoryEnvironmentOverrides.insert(categoryName, environment);
+}
+
+/*!
\internal
Installs logging rules as specified in \a content.
*/
@@ -451,8 +465,16 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat)
// qt.debug=false
if (const char *categoryName = cat->categoryName()) {
// == "qt" or startsWith("qt.")
- if (strcmp(categoryName, "qt") == 0 || strncmp(categoryName, "qt.", 3) == 0)
+ if (strcmp(categoryName, "qt") == 0) {
debug = false;
+ } else if (strncmp(categoryName, "qt.", 3) == 0) {
+ // may be overridden
+ auto it = reg->qtCategoryEnvironmentOverrides.find(categoryName);
+ if (it == reg->qtCategoryEnvironmentOverrides.end())
+ debug = false;
+ else
+ debug = qEnvironmentVariableIntValue(it.value().data());
+ }
}
const auto categoryName = QLatin1String(cat->categoryName());