diff options
author | Kai Koehne <kai.koehne@digia.com> | 2014-02-28 17:14:17 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-03-13 13:26:38 +0100 |
commit | 490298e93901eac0eba8c1156e9f9d6f2ccb6b11 (patch) | |
tree | 695ef98ff884127f9124b4d847aed1efc7587bd8 /src/corelib/io | |
parent | 19693362e7b345d417554c6497e5117f2b189be5 (diff) |
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 <Friedemann.Kleint@digia.com>
Reviewed-by: Jerome Pasion <jerome.pasion@digia.com>
Reviewed-by: Alex Blasche <alexander.blasche@digia.com>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io')
-rw-r--r-- | src/corelib/io/qloggingcategory.cpp | 3 | ||||
-rw-r--r-- | src/corelib/io/qloggingregistry.cpp | 23 |
2 files changed, 26 insertions, 0 deletions
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 <QtCore/qfile.h> #include <QtCore/qstandardpaths.h> #include <QtCore/qtextstream.h> +#include <QtCore/qdir.h> + +// 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(); |