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:
parent
19693362e7
commit
490298e939
@ -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
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user