QLoggingRegistry: Look up logging configuration in Qt data path
Distributions like Fedora would like to disable logging globally, without having to patch Qt. Fedora right now therefore adds a /etc/xdg/qtlogging.ini file, which unfortunately though also messes with Qt versions compiled by the user. This patch lets QLoggingRegistry look up logging configurations also in QLibraryInfo::DataPath, which would allow to tweak the values per Qt installation. See also https://bugzilla.redhat.com/show_bug.cgi?id=1227295 Change-Id: I0fca304a47f45739d0c08a9e4e715673bf10aa80 Reviewed-by: Alex Blasche <alexander.blasche@theqtcompany.com>
This commit is contained in:
parent
5c95c2077c
commit
cb6ab05648
@ -157,6 +157,7 @@ static void setBoolLane(QBasicAtomicInt *atomic, bool enable, int shift)
|
||||
|
||||
Order of evaluation:
|
||||
\list
|
||||
\li [QLibraryInfo::DataPath]/qtlogging.ini
|
||||
\li QtProject/qtlogging.ini
|
||||
\li \l setFilterRules()
|
||||
\li \c QT_LOGGING_CONF
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include "qloggingregistry_p.h"
|
||||
|
||||
#include <QtCore/qfile.h>
|
||||
#include <QtCore/qlibraryinfo.h>
|
||||
#include <QtCore/qstandardpaths.h>
|
||||
#include <QtCore/qtextstream.h>
|
||||
#include <QtCore/qdir.h>
|
||||
@ -247,6 +248,21 @@ static bool qtLoggingDebug()
|
||||
return debugEnv;
|
||||
}
|
||||
|
||||
static QVector<QLoggingRule> loadRulesFromFile(const QString &filePath)
|
||||
{
|
||||
QFile file(filePath);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
if (qtLoggingDebug())
|
||||
debugMsg("Loading \"%s\" ...",
|
||||
QDir::toNativeSeparators(file.fileName()).toUtf8().constData());
|
||||
QTextStream stream(&file);
|
||||
QLoggingSettingsParser parser;
|
||||
parser.setContent(stream);
|
||||
return parser.rules();
|
||||
}
|
||||
return QVector<QLoggingRule>();
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Initializes the rules database by loading
|
||||
@ -256,18 +272,9 @@ void QLoggingRegistry::init()
|
||||
{
|
||||
// get rules from environment
|
||||
const QByteArray rulesFilePath = qgetenv("QT_LOGGING_CONF");
|
||||
if (!rulesFilePath.isEmpty()) {
|
||||
QFile file(QFile::decodeName(rulesFilePath));
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
if (qtLoggingDebug())
|
||||
debugMsg("Loading \"%s\" ...",
|
||||
QDir::toNativeSeparators(file.fileName()).toUtf8().constData());
|
||||
QTextStream stream(&file);
|
||||
QLoggingSettingsParser parser;
|
||||
parser.setContent(stream);
|
||||
envRules = parser.rules();
|
||||
}
|
||||
}
|
||||
if (!rulesFilePath.isEmpty())
|
||||
envRules = loadRulesFromFile(QFile::decodeName(rulesFilePath));
|
||||
|
||||
const QByteArray rulesSrc = qgetenv("QT_LOGGING_RULES").replace(';', '\n');
|
||||
if (!rulesSrc.isEmpty()) {
|
||||
QTextStream stream(rulesSrc);
|
||||
@ -277,23 +284,22 @@ void QLoggingRegistry::init()
|
||||
envRules += parser.rules();
|
||||
}
|
||||
|
||||
// get rules from qt configuration
|
||||
QString envPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation,
|
||||
QStringLiteral("QtProject/qtlogging.ini"));
|
||||
if (!envPath.isEmpty()) {
|
||||
QFile file(envPath);
|
||||
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
if (qtLoggingDebug())
|
||||
debugMsg("Loading \"%s\" ...",
|
||||
QDir::toNativeSeparators(envPath).toUtf8().constData());
|
||||
QTextStream stream(&file);
|
||||
QLoggingSettingsParser parser;
|
||||
parser.setContent(stream);
|
||||
configRules = parser.rules();
|
||||
}
|
||||
}
|
||||
const QString configFileName = QStringLiteral("qtlogging.ini");
|
||||
|
||||
if (!envRules.isEmpty() || !configRules.isEmpty()) {
|
||||
#if !defined(QT_BOOTSTRAPPED)
|
||||
// get rules from Qt data configuration path
|
||||
const QString qtConfigPath
|
||||
= QDir(QLibraryInfo::location(QLibraryInfo::DataPath)).absoluteFilePath(configFileName);
|
||||
qtConfigRules = loadRulesFromFile(qtConfigPath);
|
||||
#endif
|
||||
|
||||
// get rules from user's/system configuration
|
||||
const QString envPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation,
|
||||
QString::fromLatin1("QtProject/") + configFileName);
|
||||
if (!envPath.isEmpty())
|
||||
configRules = loadRulesFromFile(envPath);
|
||||
|
||||
if (!envRules.isEmpty() || !qtConfigRules.isEmpty() || !configRules.isEmpty()) {
|
||||
QMutexLocker locker(®istryMutex);
|
||||
updateRules();
|
||||
}
|
||||
@ -356,7 +362,7 @@ void QLoggingRegistry::updateRules()
|
||||
if (categoryFilter != defaultCategoryFilter)
|
||||
return;
|
||||
|
||||
rules = configRules + apiRules + envRules;
|
||||
rules = qtConfigRules + configRules + apiRules + envRules;
|
||||
|
||||
foreach (QLoggingCategory *cat, categories.keys())
|
||||
(*categoryFilter)(cat);
|
||||
|
@ -122,6 +122,7 @@ private:
|
||||
|
||||
QMutex registryMutex;
|
||||
|
||||
QVector<QLoggingRule> qtConfigRules;
|
||||
QVector<QLoggingRule> configRules;
|
||||
QVector<QLoggingRule> envRules;
|
||||
QVector<QLoggingRule> apiRules;
|
||||
|
Loading…
x
Reference in New Issue
Block a user