diff options
Diffstat (limited to 'src/corelib/io/qloggingregistry.cpp')
-rw-r--r-- | src/corelib/io/qloggingregistry.cpp | 57 |
1 files changed, 37 insertions, 20 deletions
diff --git a/src/corelib/io/qloggingregistry.cpp b/src/corelib/io/qloggingregistry.cpp index 9805722213..b4181a2fa6 100644 --- a/src/corelib/io/qloggingregistry.cpp +++ b/src/corelib/io/qloggingregistry.cpp @@ -32,8 +32,7 @@ Q_GLOBAL_STATIC(QLoggingRegistry, qtLoggingRegistry) \internal Constructs a logging rule with default values. */ -QLoggingRule::QLoggingRule() : - enabled(false) +QLoggingRule::QLoggingRule() { } @@ -41,9 +40,7 @@ QLoggingRule::QLoggingRule() : \internal Constructs a logging rule. */ -QLoggingRule::QLoggingRule(QStringView pattern, bool enabled) : - messageType(-1), - enabled(enabled) +QLoggingRule::QLoggingRule(QStringView pattern, bool enabled) : enabled(enabled) { parse(pattern); } @@ -67,7 +64,7 @@ int QLoggingRule::pass(QLatin1StringView cat, QtMsgType msgType) const return 0; } - const int idx = cat.indexOf(category); + const qsizetype idx = cat.indexOf(category); if (idx >= 0) { if (flags == MidFilter) { // matches somewhere @@ -194,7 +191,7 @@ void QLoggingSettingsParser::parseNextLine(QStringView line) } if (m_inRulesSection) { - int equalPos = line.indexOf(u'='); + const qsizetype equalPos = line.indexOf(u'='); if (equalPos != -1) { if (line.lastIndexOf(u'=') == equalPos) { const auto key = line.left(equalPos).trimmed(); @@ -244,20 +241,29 @@ QLoggingRegistry::QLoggingRegistry() static bool qtLoggingDebug() { - static const bool debugEnv = qEnvironmentVariableIsSet("QT_LOGGING_DEBUG"); + static const bool debugEnv = [] { + bool debug = qEnvironmentVariableIsSet("QT_LOGGING_DEBUG"); + if (debug) + debugMsg("QT_LOGGING_DEBUG environment variable is set."); + return debug; + }(); return debugEnv; } static QList<QLoggingRule> loadRulesFromFile(const QString &filePath) { + if (qtLoggingDebug()) { + debugMsg("Checking \"%s\" for rules", + QDir::toNativeSeparators(filePath).toUtf8().constData()); + } + 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); + if (qtLoggingDebug()) + debugMsg("Loaded %td rules", static_cast<ptrdiff_t>(parser.rules().size())); return parser.rules(); } return QList<QLoggingRule>(); @@ -270,19 +276,30 @@ static QList<QLoggingRule> loadRulesFromFile(const QString &filePath) */ void QLoggingRegistry::initializeRules() { + if (qtLoggingDebug()) { + debugMsg("Initializing the rules database ..."); + debugMsg("Checking %s environment variable", "QTLOGGING_CONF"); + } QList<QLoggingRule> er, qr, cr; // get rules from environment const QByteArray rulesFilePath = qgetenv("QT_LOGGING_CONF"); if (!rulesFilePath.isEmpty()) er = loadRulesFromFile(QFile::decodeName(rulesFilePath)); + if (qtLoggingDebug()) + debugMsg("Checking %s environment variable", "QT_LOGGING_RULES"); + const QByteArray rulesSrc = qgetenv("QT_LOGGING_RULES").replace(';', '\n'); if (!rulesSrc.isEmpty()) { - QTextStream stream(rulesSrc); - QLoggingSettingsParser parser; - parser.setImplicitRulesSection(true); - parser.setContent(stream); - er += parser.rules(); + QTextStream stream(rulesSrc); + QLoggingSettingsParser parser; + parser.setImplicitRulesSection(true); + parser.setContent(stream); + + if (qtLoggingDebug()) + debugMsg("Loaded %td rules", static_cast<ptrdiff_t>(parser.rules().size())); + + er += parser.rules(); } const QString configFileName = QStringLiteral("qtlogging.ini"); @@ -347,10 +364,10 @@ void QLoggingRegistry::unregisterCategory(QLoggingCategory *cat) for enabling debugging by default for category \a categoryName. The category name must start with "qt." */ -void QLoggingRegistry::registerEnvironmentOverrideForCategory(QByteArrayView categoryName, - QByteArrayView environment) +void QLoggingRegistry::registerEnvironmentOverrideForCategory(const char *categoryName, + const char *environment) { - qtCategoryEnvironmentOverrides.insert(categoryName, environment); + qtCategoryEnvironmentOverrides.insert_or_assign(categoryName, environment); } /*! @@ -442,7 +459,7 @@ void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat) if (it == reg->qtCategoryEnvironmentOverrides.end()) debug = false; else - debug = qEnvironmentVariableIntValue(it.value().data()); + debug = qEnvironmentVariableIntValue(it->second); } } |