From 490298e93901eac0eba8c1156e9f9d6f2ccb6b11 Mon Sep 17 00:00:00 2001 From: Kai Koehne Date: Fri, 28 Feb 2014 17:14:17 +0100 Subject: [PATCH] Optionally print from where logging rules are loaded Tell the user from where logging configurations are loaded from if the QT_LOGGING_DEBUG environment variable is set. This allows 'debugging' of the logging rules database, because it's very simple to e.g. silence all debug messages by adding a logging configuration file somewhere, and forget about it. Change-Id: Iee34031d531462060b5603e2210e01fd40952c63 Reviewed-by: Friedemann Kleint Reviewed-by: Jerome Pasion Reviewed-by: Alex Blasche Reviewed-by: Thiago Macieira --- src/corelib/io/qloggingcategory.cpp | 3 +++ src/corelib/io/qloggingregistry.cpp | 23 +++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/corelib/io/qloggingcategory.cpp b/src/corelib/io/qloggingcategory.cpp index eb8aeaca50..7104dcdc93 100644 --- a/src/corelib/io/qloggingcategory.cpp +++ b/src/corelib/io/qloggingcategory.cpp @@ -137,6 +137,9 @@ Q_GLOBAL_STATIC_WITH_ARGS(QLoggingCategory, qtDefaultCategory, QCoreApplication::applicationDirPath() + \c "/data" \endlist + Set the \c QT_LOGGING_DEBUG environment variable to see from where + logging rules are loaded. + \section2 Installing a Custom Filter As a lower-level alternative to the text rules you can also implement a diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp index c5405d698c..6e195d29cb 100644 --- a/src/corelib/io/qloggingregistry.cpp +++ b/src/corelib/io/qloggingregistry.cpp @@ -45,6 +45,13 @@ #include #include #include +#include + +// We can't use the default macros because this would lead to recursion. +// Instead let's define our own one that unconditionally logs... +#define debugMsg QMessageLogger(__FILE__, __LINE__, __FUNCTION__, "qt.core.logging").debug +#define warnMsg QMessageLogger(__FILE__, __LINE__, __FUNCTION__, "qt.core.logging").warning + QT_BEGIN_NAMESPACE @@ -232,6 +239,12 @@ QLoggingRegistry::QLoggingRegistry() { } +static bool qtLoggingDebug() +{ + static const bool debugEnv = qEnvironmentVariableIsSet("QT_LOGGING_DEBUG"); + return debugEnv; +} + /*! \internal Initializes the rules database by loading @@ -247,6 +260,9 @@ void QLoggingRegistry::init() QTextStream stream(&file); QLoggingSettingsParser parser; parser.setContent(stream); + if (qtLoggingDebug()) + debugMsg("Loading \"%s\" ...", + QDir::toNativeSeparators(file.fileName()).toUtf8().constData()); envRules = parser.rules(); } } @@ -260,6 +276,9 @@ void QLoggingRegistry::init() QTextStream stream(&file); QLoggingSettingsParser parser; parser.setContent(stream); + if (qtLoggingDebug()) + debugMsg("Loading \"%s\" ...", + QDir::toNativeSeparators(envPath).toUtf8().constData()); configRules = parser.rules(); } } @@ -308,6 +327,10 @@ void QLoggingRegistry::setApiRules(const QString &content) parser.setContent(content); QMutexLocker locker(®istryMutex); + + if (qtLoggingDebug()) + debugMsg("Loading logging rules set by Qt API ..."); + apiRules = parser.rules(); updateRules();