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>
This commit is contained in:
Kai Koehne 2014-02-28 17:14:17 +01:00 committed by The Qt Project
parent 19693362e7
commit 490298e939
2 changed files with 26 additions and 0 deletions

View File

@ -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

View File

@ -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(&registryMutex);
if (qtLoggingDebug())
debugMsg("Loading logging rules set by Qt API ...");
apiRules = parser.rules();
updateRules();