| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qloggingregistry.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||||||||||||||
| 2 | ** | - | ||||||||||||||||||
| 3 | ** Copyright (C) 2015 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: http://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL21$ | - | ||||||||||||||||||
| 9 | ** Commercial License Usage | - | ||||||||||||||||||
| 10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||||||||
| 11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||||||||
| 12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||||||||
| 13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||||||||
| 14 | ** and conditions see http://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at http://www.qt.io/contact-us. | - | ||||||||||||||||||
| 16 | ** | - | ||||||||||||||||||
| 17 | ** GNU Lesser General Public License Usage | - | ||||||||||||||||||
| 18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||||||||
| 19 | ** General Public License version 2.1 or version 3 as published by the Free | - | ||||||||||||||||||
| 20 | ** Software Foundation and appearing in the file LICENSE.LGPLv21 and | - | ||||||||||||||||||
| 21 | ** LICENSE.LGPLv3 included in the packaging of this file. Please review the | - | ||||||||||||||||||
| 22 | ** following information to ensure the GNU Lesser General Public License | - | ||||||||||||||||||
| 23 | ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and | - | ||||||||||||||||||
| 24 | ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | - | ||||||||||||||||||
| 25 | ** | - | ||||||||||||||||||
| 26 | ** As a special exception, The Qt Company gives you certain additional | - | ||||||||||||||||||
| 27 | ** rights. These rights are described in The Qt Company LGPL Exception | - | ||||||||||||||||||
| 28 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. | - | ||||||||||||||||||
| 29 | ** | - | ||||||||||||||||||
| 30 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 31 | ** | - | ||||||||||||||||||
| 32 | ****************************************************************************/ | - | ||||||||||||||||||
| 33 | - | |||||||||||||||||||
| 34 | #include "qloggingregistry_p.h" | - | ||||||||||||||||||
| 35 | - | |||||||||||||||||||
| 36 | #include <QtCore/qfile.h> | - | ||||||||||||||||||
| 37 | #include <QtCore/qlibraryinfo.h> | - | ||||||||||||||||||
| 38 | #include <QtCore/qstandardpaths.h> | - | ||||||||||||||||||
| 39 | #include <QtCore/qtextstream.h> | - | ||||||||||||||||||
| 40 | #include <QtCore/qdir.h> | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | // We can't use the default macros because this would lead to recursion. | - | ||||||||||||||||||
| 43 | // Instead let's define our own one that unconditionally logs... | - | ||||||||||||||||||
| 44 | #define debugMsg QMessageLogger(__FILE__, __LINE__, __FUNCTION__, "qt.core.logging").debug | - | ||||||||||||||||||
| 45 | #define warnMsg QMessageLogger(__FILE__, __LINE__, __FUNCTION__, "qt.core.logging").warning | - | ||||||||||||||||||
| 46 | - | |||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 49 | - | |||||||||||||||||||
| 50 | Q_GLOBAL_STATIC(QLoggingRegistry, qtLoggingRegistry) executed 992 times by 430 tests: end of blockExecuted by:
executed 992 times by 430 tests: guard.store(QtGlobalStatic::Destroyed);Executed by:
executed 244159 times by 547 tests: return &holder.value;Executed by:
| 0-244159 | ||||||||||||||||||
| 51 | - | |||||||||||||||||||
| 52 | /*! | - | ||||||||||||||||||
| 53 | \internal | - | ||||||||||||||||||
| 54 | Constructs a logging rule with default values. | - | ||||||||||||||||||
| 55 | */ | - | ||||||||||||||||||
| 56 | QLoggingRule::QLoggingRule() : | - | ||||||||||||||||||
| 57 | enabled(false) | - | ||||||||||||||||||
| 58 | { | - | ||||||||||||||||||
| 59 | } never executed: end of block | 0 | ||||||||||||||||||
| 60 | - | |||||||||||||||||||
| 61 | /*! | - | ||||||||||||||||||
| 62 | \internal | - | ||||||||||||||||||
| 63 | Constructs a logging rule. | - | ||||||||||||||||||
| 64 | */ | - | ||||||||||||||||||
| 65 | QLoggingRule::QLoggingRule(const QStringRef &pattern, bool enabled) : | - | ||||||||||||||||||
| 66 | messageType(-1), | - | ||||||||||||||||||
| 67 | enabled(enabled) | - | ||||||||||||||||||
| 68 | { | - | ||||||||||||||||||
| 69 | parse(pattern); | - | ||||||||||||||||||
| 70 | } executed 24116 times by 2 tests: end of blockExecuted by:
| 24116 | ||||||||||||||||||
| 71 | - | |||||||||||||||||||
| 72 | /*! | - | ||||||||||||||||||
| 73 | \internal | - | ||||||||||||||||||
| 74 | Return value 1 means filter passed, 0 means filter doesn't influence this | - | ||||||||||||||||||
| 75 | category, -1 means category doesn't pass this filter. | - | ||||||||||||||||||
| 76 | */ | - | ||||||||||||||||||
| 77 | int QLoggingRule::pass(const QString &cat, QtMsgType msgType) const | - | ||||||||||||||||||
| 78 | { | - | ||||||||||||||||||
| 79 | // check message type | - | ||||||||||||||||||
| 80 | if (messageType > -1 && messageType != msgType)
| 132-865359 | ||||||||||||||||||
| 81 | return 0; executed 384 times by 2 tests: return 0;Executed by:
| 384 | ||||||||||||||||||
| 82 | - | |||||||||||||||||||
| 83 | if (flags == FullText) {
| 1050-864441 | ||||||||||||||||||
| 84 | // full match | - | ||||||||||||||||||
| 85 | if (category == cat)
| 127-923 | ||||||||||||||||||
| 86 | return (enabled ? 1 : -1); executed 127 times by 2 tests: return (enabled ? 1 : -1);Executed by:
| 44-127 | ||||||||||||||||||
| 87 | else | - | ||||||||||||||||||
| 88 | return 0; executed 923 times by 2 tests: return 0;Executed by:
| 923 | ||||||||||||||||||
| 89 | } | - | ||||||||||||||||||
| 90 | - | |||||||||||||||||||
| 91 | const int idx = cat.indexOf(category); | - | ||||||||||||||||||
| 92 | if (idx >= 0) {
| 288174-576267 | ||||||||||||||||||
| 93 | if (flags == MidFilter) {
| 75-288099 | ||||||||||||||||||
| 94 | // matches somewhere | - | ||||||||||||||||||
| 95 | if (idx >= 0)
| 0-75 | ||||||||||||||||||
| 96 | return (enabled ? 1 : -1); executed 75 times by 2 tests: return (enabled ? 1 : -1);Executed by:
| 27-75 | ||||||||||||||||||
| 97 | } else if (flags == LeftFilter) { never executed: end of block
| 0-288081 | ||||||||||||||||||
| 98 | // matches left | - | ||||||||||||||||||
| 99 | if (idx == 0)
| 0-288081 | ||||||||||||||||||
| 100 | return (enabled ? 1 : -1); executed 288081 times by 2 tests: return (enabled ? 1 : -1);Executed by:
| 144040-288081 | ||||||||||||||||||
| 101 | } else if (flags == RightFilter) { never executed: end of block
| 0-18 | ||||||||||||||||||
| 102 | // matches right | - | ||||||||||||||||||
| 103 | if (idx == (cat.count() - category.count()))
| 2-16 | ||||||||||||||||||
| 104 | return (enabled ? 1 : -1); executed 16 times by 2 tests: return (enabled ? 1 : -1);Executed by:
| 7-16 | ||||||||||||||||||
| 105 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 106 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 107 | return 0; executed 576269 times by 2 tests: return 0;Executed by:
| 576269 | ||||||||||||||||||
| 108 | } | - | ||||||||||||||||||
| 109 | - | |||||||||||||||||||
| 110 | /*! | - | ||||||||||||||||||
| 111 | \internal | - | ||||||||||||||||||
| 112 | Parses \a pattern. | - | ||||||||||||||||||
| 113 | Allowed is f.ex.: | - | ||||||||||||||||||
| 114 | qt.core.io.debug FullText, QtDebugMsg | - | ||||||||||||||||||
| 115 | qt.core.* LeftFilter, all types | - | ||||||||||||||||||
| 116 | *.io.warning RightFilter, QtWarningMsg | - | ||||||||||||||||||
| 117 | *.core.* MidFilter | - | ||||||||||||||||||
| 118 | */ | - | ||||||||||||||||||
| 119 | void QLoggingRule::parse(const QStringRef &pattern) | - | ||||||||||||||||||
| 120 | { | - | ||||||||||||||||||
| 121 | QStringRef p; | - | ||||||||||||||||||
| 122 | - | |||||||||||||||||||
| 123 | // strip trailing ".messagetype" | - | ||||||||||||||||||
| 124 | if (pattern.endsWith(QLatin1String(".debug"))) {
| 14-24102 | ||||||||||||||||||
| 125 | p = QStringRef(pattern.string(), pattern.position(), | - | ||||||||||||||||||
| 126 | pattern.length() - 6); // strlen(".debug") | - | ||||||||||||||||||
| 127 | messageType = QtDebugMsg; | - | ||||||||||||||||||
| 128 | } else if (pattern.endsWith(QLatin1String(".info"))) { executed 14 times by 2 tests: end of blockExecuted by:
| 4-24098 | ||||||||||||||||||
| 129 | p = QStringRef(pattern.string(), pattern.position(), | - | ||||||||||||||||||
| 130 | pattern.length() - 5); // strlen(".info") | - | ||||||||||||||||||
| 131 | messageType = QtInfoMsg; | - | ||||||||||||||||||
| 132 | } else if (pattern.endsWith(QLatin1String(".warning"))) { executed 4 times by 1 test: end of blockExecuted by:
| 4-24089 | ||||||||||||||||||
| 133 | p = QStringRef(pattern.string(), pattern.position(), | - | ||||||||||||||||||
| 134 | pattern.length() - 8); // strlen(".warning") | - | ||||||||||||||||||
| 135 | messageType = QtWarningMsg; | - | ||||||||||||||||||
| 136 | } else if (pattern.endsWith(QLatin1String(".critical"))) { executed 9 times by 2 tests: end of blockExecuted by:
| 4-24085 | ||||||||||||||||||
| 137 | p = QStringRef(pattern.string(), pattern.position(), | - | ||||||||||||||||||
| 138 | pattern.length() - 9); // strlen(".critical") | - | ||||||||||||||||||
| 139 | messageType = QtCriticalMsg; | - | ||||||||||||||||||
| 140 | } else { executed 4 times by 2 tests: end of blockExecuted by:
| 4 | ||||||||||||||||||
| 141 | p = pattern; | - | ||||||||||||||||||
| 142 | } executed 24085 times by 2 tests: end of blockExecuted by:
| 24085 | ||||||||||||||||||
| 143 | - | |||||||||||||||||||
| 144 | if (!p.contains(QLatin1Char('*'))) {
| 63-24053 | ||||||||||||||||||
| 145 | flags = FullText; | - | ||||||||||||||||||
| 146 | } else { executed 63 times by 2 tests: end of blockExecuted by:
| 63 | ||||||||||||||||||
| 147 | if (p.endsWith(QLatin1Char('*'))) {
| 13-24040 | ||||||||||||||||||
| 148 | flags |= LeftFilter; | - | ||||||||||||||||||
| 149 | p = QStringRef(p.string(), p.position(), p.length() - 1); | - | ||||||||||||||||||
| 150 | } executed 24040 times by 2 tests: end of blockExecuted by:
| 24040 | ||||||||||||||||||
| 151 | if (p.startsWith(QLatin1Char('*'))) {
| 25-24028 | ||||||||||||||||||
| 152 | flags |= RightFilter; | - | ||||||||||||||||||
| 153 | p = QStringRef(p.string(), p.position() + 1, p.length() - 1); | - | ||||||||||||||||||
| 154 | } executed 25 times by 2 tests: end of blockExecuted by:
| 25 | ||||||||||||||||||
| 155 | if (p.contains(QLatin1Char('*'))) // '*' only supported at start/end
| 3-24050 | ||||||||||||||||||
| 156 | flags = 0; executed 3 times by 1 test: flags = 0;Executed by:
| 3 | ||||||||||||||||||
| 157 | } executed 24053 times by 2 tests: end of blockExecuted by:
| 24053 | ||||||||||||||||||
| 158 | - | |||||||||||||||||||
| 159 | category = p.toString(); | - | ||||||||||||||||||
| 160 | } executed 24116 times by 2 tests: end of blockExecuted by:
| 24116 | ||||||||||||||||||
| 161 | - | |||||||||||||||||||
| 162 | /*! | - | ||||||||||||||||||
| 163 | \class QLoggingSettingsParser | - | ||||||||||||||||||
| 164 | \since 5.3 | - | ||||||||||||||||||
| 165 | \internal | - | ||||||||||||||||||
| 166 | - | |||||||||||||||||||
| 167 | Parses a .ini file with the following format: | - | ||||||||||||||||||
| 168 | - | |||||||||||||||||||
| 169 | [rules] | - | ||||||||||||||||||
| 170 | rule1=[true|false] | - | ||||||||||||||||||
| 171 | rule2=[true|false] | - | ||||||||||||||||||
| 172 | ... | - | ||||||||||||||||||
| 173 | - | |||||||||||||||||||
| 174 | [rules] is the default section, and therefore optional. | - | ||||||||||||||||||
| 175 | */ | - | ||||||||||||||||||
| 176 | - | |||||||||||||||||||
| 177 | /*! | - | ||||||||||||||||||
| 178 | \internal | - | ||||||||||||||||||
| 179 | Parses configuration from \a content. | - | ||||||||||||||||||
| 180 | */ | - | ||||||||||||||||||
| 181 | void QLoggingSettingsParser::setContent(const QString &content) | - | ||||||||||||||||||
| 182 | { | - | ||||||||||||||||||
| 183 | QString content_ = content; | - | ||||||||||||||||||
| 184 | QTextStream stream(&content_, QIODevice::ReadOnly); | - | ||||||||||||||||||
| 185 | setContent(stream); | - | ||||||||||||||||||
| 186 | } executed 24025 times by 2 tests: end of blockExecuted by:
| 24025 | ||||||||||||||||||
| 187 | - | |||||||||||||||||||
| 188 | /*! | - | ||||||||||||||||||
| 189 | \internal | - | ||||||||||||||||||
| 190 | Parses configuration from \a stream. | - | ||||||||||||||||||
| 191 | */ | - | ||||||||||||||||||
| 192 | void QLoggingSettingsParser::setContent(QTextStream &stream) | - | ||||||||||||||||||
| 193 | { | - | ||||||||||||||||||
| 194 | _rules.clear(); | - | ||||||||||||||||||
| 195 | while (!stream.atEnd()) {
| 24031-24089 | ||||||||||||||||||
| 196 | QString line = stream.readLine(); | - | ||||||||||||||||||
| 197 | - | |||||||||||||||||||
| 198 | // Remove all whitespace from line | - | ||||||||||||||||||
| 199 | line = line.simplified(); | - | ||||||||||||||||||
| 200 | line.remove(QLatin1Char(' ')); | - | ||||||||||||||||||
| 201 | - | |||||||||||||||||||
| 202 | // comment | - | ||||||||||||||||||
| 203 | if (line.startsWith(QLatin1Char(';')))
| 0-24089 | ||||||||||||||||||
| 204 | continue; never executed: continue; | 0 | ||||||||||||||||||
| 205 | - | |||||||||||||||||||
| 206 | if (line.startsWith(QLatin1Char('[')) && line.endsWith(QLatin1Char(']'))) {
| 0-24080 | ||||||||||||||||||
| 207 | // new section | - | ||||||||||||||||||
| 208 | _section = line.mid(1, line.size() - 2); | - | ||||||||||||||||||
| 209 | continue; executed 9 times by 1 test: continue;Executed by:
| 9 | ||||||||||||||||||
| 210 | } | - | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | if (_section.toLower() == QLatin1String("rules")) {
| 1-24079 | ||||||||||||||||||
| 213 | int equalPos = line.indexOf(QLatin1Char('=')); | - | ||||||||||||||||||
| 214 | if (equalPos != -1) {
| 0-24079 | ||||||||||||||||||
| 215 | if (line.lastIndexOf(QLatin1Char('=')) == equalPos) {
| 0-24079 | ||||||||||||||||||
| 216 | const QStringRef pattern = line.leftRef(equalPos); | - | ||||||||||||||||||
| 217 | const QStringRef valueStr = line.midRef(equalPos + 1); | - | ||||||||||||||||||
| 218 | int value = -1; | - | ||||||||||||||||||
| 219 | if (valueStr == QLatin1String("true"))
| 12029-12050 | ||||||||||||||||||
| 220 | value = 1; executed 12029 times by 2 tests: value = 1;Executed by:
| 12029 | ||||||||||||||||||
| 221 | else if (valueStr == QLatin1String("false"))
| 9-12041 | ||||||||||||||||||
| 222 | value = 0; executed 12041 times by 2 tests: value = 0;Executed by:
| 12041 | ||||||||||||||||||
| 223 | QLoggingRule rule(pattern, (value == 1)); | - | ||||||||||||||||||
| 224 | if (rule.flags != 0 && (value != -1))
| 1-24078 | ||||||||||||||||||
| 225 | _rules.append(rule); executed 24069 times by 2 tests: _rules.append(rule);Executed by:
| 24069 | ||||||||||||||||||
| 226 | else | - | ||||||||||||||||||
| 227 | warnMsg("Ignoring malformed logging rule: '%s'", line.toUtf8().constData()); executed 10 times by 2 tests: QMessageLogger(__FILE__, 227, __FUNCTION__, "qt.core.logging").warning("Ignoring malformed logging rule: '%s'", line.toUtf8().constData());Executed by:
| 10 | ||||||||||||||||||
| 228 | } else { | - | ||||||||||||||||||
| 229 | warnMsg("Ignoring malformed logging rule: '%s'", line.toUtf8().constData()); | - | ||||||||||||||||||
| 230 | } never executed: end of block | 0 | ||||||||||||||||||
| 231 | } | - | ||||||||||||||||||
| 232 | } executed 24079 times by 2 tests: end of blockExecuted by:
| 24079 | ||||||||||||||||||
| 233 | } executed 24080 times by 2 tests: end of blockExecuted by:
| 24080 | ||||||||||||||||||
| 234 | } executed 24031 times by 2 tests: end of blockExecuted by:
| 24031 | ||||||||||||||||||
| 235 | - | |||||||||||||||||||
| 236 | /*! | - | ||||||||||||||||||
| 237 | \internal | - | ||||||||||||||||||
| 238 | QLoggingRegistry constructor | - | ||||||||||||||||||
| 239 | */ | - | ||||||||||||||||||
| 240 | QLoggingRegistry::QLoggingRegistry() | - | ||||||||||||||||||
| 241 | : categoryFilter(defaultCategoryFilter) | - | ||||||||||||||||||
| 242 | { | - | ||||||||||||||||||
| 243 | } executed 672 times by 33 tests: end of blockExecuted by:
| 672 | ||||||||||||||||||
| 244 | - | |||||||||||||||||||
| 245 | static bool qtLoggingDebug() | - | ||||||||||||||||||
| 246 | { | - | ||||||||||||||||||
| 247 | static const bool debugEnv = qEnvironmentVariableIsSet("QT_LOGGING_DEBUG"); | - | ||||||||||||||||||
| 248 | return debugEnv; executed 24023 times by 2 tests: return debugEnv;Executed by:
| 24023 | ||||||||||||||||||
| 249 | } | - | ||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | static QVector<QLoggingRule> loadRulesFromFile(const QString &filePath) | - | ||||||||||||||||||
| 252 | { | - | ||||||||||||||||||
| 253 | QFile file(filePath); | - | ||||||||||||||||||
| 254 | if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
| 4-870 | ||||||||||||||||||
| 255 | if (qtLoggingDebug())
| 0-4 | ||||||||||||||||||
| 256 | debugMsg("Loading \"%s\" ...", never executed: QMessageLogger(__FILE__, 256, __FUNCTION__, "qt.core.logging").debug("Loading \"%s\" ...", QDir::toNativeSeparators(file.fileName()).toUtf8().constData()); | 0 | ||||||||||||||||||
| 257 | QDir::toNativeSeparators(file.fileName()).toUtf8().constData()); never executed: QMessageLogger(__FILE__, 256, __FUNCTION__, "qt.core.logging").debug("Loading \"%s\" ...", QDir::toNativeSeparators(file.fileName()).toUtf8().constData()); | 0 | ||||||||||||||||||
| 258 | QTextStream stream(&file); | - | ||||||||||||||||||
| 259 | QLoggingSettingsParser parser; | - | ||||||||||||||||||
| 260 | parser.setContent(stream); | - | ||||||||||||||||||
| 261 | return parser.rules(); executed 4 times by 1 test: return parser.rules();Executed by:
| 4 | ||||||||||||||||||
| 262 | } | - | ||||||||||||||||||
| 263 | return QVector<QLoggingRule>(); executed 870 times by 23 tests: return QVector<QLoggingRule>();Executed by:
| 870 | ||||||||||||||||||
| 264 | } | - | ||||||||||||||||||
| 265 | - | |||||||||||||||||||
| 266 | /*! | - | ||||||||||||||||||
| 267 | \internal | - | ||||||||||||||||||
| 268 | Initializes the rules database by loading | - | ||||||||||||||||||
| 269 | $QT_LOGGING_CONF, $QT_LOGGING_RULES, and .config/QtProject/qtlogging.ini. | - | ||||||||||||||||||
| 270 | */ | - | ||||||||||||||||||
| 271 | void QLoggingRegistry::init() | - | ||||||||||||||||||
| 272 | { | - | ||||||||||||||||||
| 273 | QVector<QLoggingRule> er, qr, cr; | - | ||||||||||||||||||
| 274 | // get rules from environment | - | ||||||||||||||||||
| 275 | const QByteArray rulesFilePath = qgetenv("QT_LOGGING_CONF"); | - | ||||||||||||||||||
| 276 | if (!rulesFilePath.isEmpty())
| 3-868 | ||||||||||||||||||
| 277 | er = loadRulesFromFile(QFile::decodeName(rulesFilePath)); executed 3 times by 1 test: er = loadRulesFromFile(QFile::decodeName(rulesFilePath));Executed by:
| 3 | ||||||||||||||||||
| 278 | - | |||||||||||||||||||
| 279 | const QByteArray rulesSrc = qgetenv("QT_LOGGING_RULES").replace(';', '\n'); | - | ||||||||||||||||||
| 280 | if (!rulesSrc.isEmpty()) {
| 2-869 | ||||||||||||||||||
| 281 | QTextStream stream(rulesSrc); | - | ||||||||||||||||||
| 282 | QLoggingSettingsParser parser; | - | ||||||||||||||||||
| 283 | parser.setSection(QStringLiteral("Rules")); executed 2 times by 1 test: return qstring_literal_temp;Executed by:
| 2 | ||||||||||||||||||
| 284 | parser.setContent(stream); | - | ||||||||||||||||||
| 285 | er += parser.rules(); | - | ||||||||||||||||||
| 286 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 287 | - | |||||||||||||||||||
| 288 | const QString configFileName = QStringLiteral("qtlogging.ini"); executed 871 times by 23 tests: return qstring_literal_temp;Executed by:
| 871 | ||||||||||||||||||
| 289 | - | |||||||||||||||||||
| 290 | #if !defined(QT_BOOTSTRAPPED) | - | ||||||||||||||||||
| 291 | // get rules from Qt data configuration path | - | ||||||||||||||||||
| 292 | const QString qtConfigPath | - | ||||||||||||||||||
| 293 | = QDir(QLibraryInfo::location(QLibraryInfo::DataPath)).absoluteFilePath(configFileName); | - | ||||||||||||||||||
| 294 | qr = loadRulesFromFile(qtConfigPath); | - | ||||||||||||||||||
| 295 | #endif | - | ||||||||||||||||||
| 296 | - | |||||||||||||||||||
| 297 | // get rules from user's/system configuration | - | ||||||||||||||||||
| 298 | const QString envPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, | - | ||||||||||||||||||
| 299 | QString::fromLatin1("QtProject/") + configFileName); | - | ||||||||||||||||||
| 300 | if (!envPath.isEmpty())
| 1-869 | ||||||||||||||||||
| 301 | cr = loadRulesFromFile(envPath); executed 1 time by 1 test: cr = loadRulesFromFile(envPath);Executed by:
| 1 | ||||||||||||||||||
| 302 | - | |||||||||||||||||||
| 303 | const QMutexLocker locker(®istryMutex); | - | ||||||||||||||||||
| 304 | - | |||||||||||||||||||
| 305 | envRules = qMove(er); | - | ||||||||||||||||||
| 306 | qtConfigRules = qMove(qr); | - | ||||||||||||||||||
| 307 | configRules = qMove(cr); | - | ||||||||||||||||||
| 308 | - | |||||||||||||||||||
| 309 | if (!envRules.isEmpty() || !qtConfigRules.isEmpty() || !configRules.isEmpty()) {
| 0-867 | ||||||||||||||||||
| 310 | updateRules(); | - | ||||||||||||||||||
| 311 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 312 | } executed 870 times by 23 tests: end of blockExecuted by:
| 870 | ||||||||||||||||||
| 313 | - | |||||||||||||||||||
| 314 | /*! | - | ||||||||||||||||||
| 315 | \internal | - | ||||||||||||||||||
| 316 | Registers a category object. | - | ||||||||||||||||||
| 317 | - | |||||||||||||||||||
| 318 | This method might be called concurrently for the same category object. | - | ||||||||||||||||||
| 319 | */ | - | ||||||||||||||||||
| 320 | void QLoggingRegistry::registerCategory(QLoggingCategory *cat, QtMsgType enableForLevel) | - | ||||||||||||||||||
| 321 | { | - | ||||||||||||||||||
| 322 | QMutexLocker locker(®istryMutex); | - | ||||||||||||||||||
| 323 | - | |||||||||||||||||||
| 324 | if (!categories.contains(cat)) {
| 0-846 | ||||||||||||||||||
| 325 | categories.insert(cat, enableForLevel); | - | ||||||||||||||||||
| 326 | (*categoryFilter)(cat); | - | ||||||||||||||||||
| 327 | } executed 846 times by 243 tests: end of blockExecuted by:
| 846 | ||||||||||||||||||
| 328 | } executed 846 times by 243 tests: end of blockExecuted by:
| 846 | ||||||||||||||||||
| 329 | - | |||||||||||||||||||
| 330 | /*! | - | ||||||||||||||||||
| 331 | \internal | - | ||||||||||||||||||
| 332 | Unregisters a category object. | - | ||||||||||||||||||
| 333 | */ | - | ||||||||||||||||||
| 334 | void QLoggingRegistry::unregisterCategory(QLoggingCategory *cat) | - | ||||||||||||||||||
| 335 | { | - | ||||||||||||||||||
| 336 | QMutexLocker locker(®istryMutex); | - | ||||||||||||||||||
| 337 | categories.remove(cat); | - | ||||||||||||||||||
| 338 | } executed 1425 times by 307 tests: end of blockExecuted by:
| 1425 | ||||||||||||||||||
| 339 | - | |||||||||||||||||||
| 340 | /*! | - | ||||||||||||||||||
| 341 | \internal | - | ||||||||||||||||||
| 342 | Installs logging rules as specified in \a content. | - | ||||||||||||||||||
| 343 | */ | - | ||||||||||||||||||
| 344 | void QLoggingRegistry::setApiRules(const QString &content) | - | ||||||||||||||||||
| 345 | { | - | ||||||||||||||||||
| 346 | QLoggingSettingsParser parser; | - | ||||||||||||||||||
| 347 | parser.setSection(QStringLiteral("Rules")); executed 24019 times by 2 tests: return qstring_literal_temp;Executed by:
| 24019 | ||||||||||||||||||
| 348 | parser.setContent(content); | - | ||||||||||||||||||
| 349 | - | |||||||||||||||||||
| 350 | if (qtLoggingDebug())
| 0-24019 | ||||||||||||||||||
| 351 | debugMsg("Loading logging rules set by QLoggingCategory::setFilterRules ..."); never executed: QMessageLogger(__FILE__, 351, __FUNCTION__, "qt.core.logging").debug("Loading logging rules set by QLoggingCategory::setFilterRules ..."); | 0 | ||||||||||||||||||
| 352 | - | |||||||||||||||||||
| 353 | const QMutexLocker locker(®istryMutex); | - | ||||||||||||||||||
| 354 | - | |||||||||||||||||||
| 355 | apiRules = parser.rules(); | - | ||||||||||||||||||
| 356 | - | |||||||||||||||||||
| 357 | updateRules(); | - | ||||||||||||||||||
| 358 | } executed 24019 times by 2 tests: end of blockExecuted by:
| 24019 | ||||||||||||||||||
| 359 | - | |||||||||||||||||||
| 360 | /*! | - | ||||||||||||||||||
| 361 | \internal | - | ||||||||||||||||||
| 362 | Activates a new set of logging rules for the default filter. | - | ||||||||||||||||||
| 363 | - | |||||||||||||||||||
| 364 | (The caller must lock registryMutex to make sure the API is thread safe.) | - | ||||||||||||||||||
| 365 | */ | - | ||||||||||||||||||
| 366 | void QLoggingRegistry::updateRules() | - | ||||||||||||||||||
| 367 | { | - | ||||||||||||||||||
| 368 | rules = qtConfigRules + configRules + apiRules + envRules; | - | ||||||||||||||||||
| 369 | - | |||||||||||||||||||
| 370 | foreach (QLoggingCategory *cat, categories.keys()) | - | ||||||||||||||||||
| 371 | (*categoryFilter)(cat); executed 216136 times by 2 tests: (*categoryFilter)(cat);Executed by:
| 216136 | ||||||||||||||||||
| 372 | } executed 24025 times by 2 tests: end of blockExecuted by:
| 24025 | ||||||||||||||||||
| 373 | - | |||||||||||||||||||
| 374 | /*! | - | ||||||||||||||||||
| 375 | \internal | - | ||||||||||||||||||
| 376 | Installs a custom filter rule. | - | ||||||||||||||||||
| 377 | */ | - | ||||||||||||||||||
| 378 | QLoggingCategory::CategoryFilter | - | ||||||||||||||||||
| 379 | QLoggingRegistry::installFilter(QLoggingCategory::CategoryFilter filter) | - | ||||||||||||||||||
| 380 | { | - | ||||||||||||||||||
| 381 | QMutexLocker locker(®istryMutex); | - | ||||||||||||||||||
| 382 | - | |||||||||||||||||||
| 383 | if (filter == 0)
| 3-4 | ||||||||||||||||||
| 384 | filter = defaultCategoryFilter; executed 3 times by 1 test: filter = defaultCategoryFilter;Executed by:
| 3 | ||||||||||||||||||
| 385 | - | |||||||||||||||||||
| 386 | QLoggingCategory::CategoryFilter old = categoryFilter; | - | ||||||||||||||||||
| 387 | categoryFilter = filter; | - | ||||||||||||||||||
| 388 | - | |||||||||||||||||||
| 389 | foreach (QLoggingCategory *cat, categories.keys()) | - | ||||||||||||||||||
| 390 | (*categoryFilter)(cat); executed 22 times by 1 test: (*categoryFilter)(cat);Executed by:
| 22 | ||||||||||||||||||
| 391 | - | |||||||||||||||||||
| 392 | return old; executed 7 times by 1 test: return old;Executed by:
| 7 | ||||||||||||||||||
| 393 | } | - | ||||||||||||||||||
| 394 | - | |||||||||||||||||||
| 395 | QLoggingRegistry *QLoggingRegistry::instance() | - | ||||||||||||||||||
| 396 | { | - | ||||||||||||||||||
| 397 | return qtLoggingRegistry(); executed 244159 times by 547 tests: return qtLoggingRegistry();Executed by:
| 244159 | ||||||||||||||||||
| 398 | } | - | ||||||||||||||||||
| 399 | - | |||||||||||||||||||
| 400 | /*! | - | ||||||||||||||||||
| 401 | \internal | - | ||||||||||||||||||
| 402 | Updates category settings according to rules. | - | ||||||||||||||||||
| 403 | - | |||||||||||||||||||
| 404 | As a category filter, it is run with registryMutex held. | - | ||||||||||||||||||
| 405 | */ | - | ||||||||||||||||||
| 406 | void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat) | - | ||||||||||||||||||
| 407 | { | - | ||||||||||||||||||
| 408 | QLoggingRegistry *reg = QLoggingRegistry::instance(); | - | ||||||||||||||||||
| 409 | Q_ASSERT(reg->categories.contains(cat)); | - | ||||||||||||||||||
| 410 | QtMsgType enableForLevel = reg->categories.value(cat); | - | ||||||||||||||||||
| 411 | - | |||||||||||||||||||
| 412 | // NB: note that the numeric values of the Qt*Msg constants are | - | ||||||||||||||||||
| 413 | // not in severity order. | - | ||||||||||||||||||
| 414 | bool debug = (enableForLevel == QtDebugMsg); | - | ||||||||||||||||||
| 415 | bool info = debug || (enableForLevel == QtInfoMsg);
| 24020-168952 | ||||||||||||||||||
| 416 | bool warning = info || (enableForLevel == QtWarningMsg);
| 1-192972 | ||||||||||||||||||
| 417 | bool critical = warning || (enableForLevel == QtCriticalMsg);
| 0-192973 | ||||||||||||||||||
| 418 | - | |||||||||||||||||||
| 419 | // hard-wired implementation of | - | ||||||||||||||||||
| 420 | // qt.*.debug=false | - | ||||||||||||||||||
| 421 | // qt.debug=false | - | ||||||||||||||||||
| 422 | if (const char *categoryName = cat->categoryName()) {
| 0-216993 | ||||||||||||||||||
| 423 | // == "qt" or startsWith("qt.") | - | ||||||||||||||||||
| 424 | if (strcmp(categoryName, "qt") == 0 || strncmp(categoryName, "qt.", 3) == 0)
| 0-216993 | ||||||||||||||||||
| 425 | debug = false; executed 360 times by 137 tests: debug = false;Executed by:
| 360 | ||||||||||||||||||
| 426 | } executed 216993 times by 243 tests: end of blockExecuted by:
| 216993 | ||||||||||||||||||
| 427 | - | |||||||||||||||||||
| 428 | QString categoryName = QLatin1String(cat->categoryName()); | - | ||||||||||||||||||
| 429 | foreach (const QLoggingRule &item, reg->rules) { | - | ||||||||||||||||||
| 430 | int filterpass = item.pass(categoryName, QtDebugMsg); | - | ||||||||||||||||||
| 431 | if (filterpass != 0)
| 72079-144381 | ||||||||||||||||||
| 432 | debug = (filterpass > 0); executed 72079 times by 2 tests: debug = (filterpass > 0);Executed by:
| 72079 | ||||||||||||||||||
| 433 | filterpass = item.pass(categoryName, QtInfoMsg); | - | ||||||||||||||||||
| 434 | if (filterpass != 0)
| 72067-144393 | ||||||||||||||||||
| 435 | info = (filterpass > 0); executed 72067 times by 2 tests: info = (filterpass > 0);Executed by:
| 72067 | ||||||||||||||||||
| 436 | filterpass = item.pass(categoryName, QtWarningMsg); | - | ||||||||||||||||||
| 437 | if (filterpass != 0)
| 72067-144393 | ||||||||||||||||||
| 438 | warning = (filterpass > 0); executed 72067 times by 2 tests: warning = (filterpass > 0);Executed by:
| 72067 | ||||||||||||||||||
| 439 | filterpass = item.pass(categoryName, QtCriticalMsg); | - | ||||||||||||||||||
| 440 | if (filterpass != 0)
| 72066-144394 | ||||||||||||||||||
| 441 | critical = (filterpass > 0); executed 72066 times by 2 tests: critical = (filterpass > 0);Executed by:
| 72066 | ||||||||||||||||||
| 442 | } executed 216460 times by 2 tests: end of blockExecuted by:
| 216460 | ||||||||||||||||||
| 443 | - | |||||||||||||||||||
| 444 | cat->setEnabled(QtDebugMsg, debug); | - | ||||||||||||||||||
| 445 | cat->setEnabled(QtInfoMsg, info); | - | ||||||||||||||||||
| 446 | cat->setEnabled(QtWarningMsg, warning); | - | ||||||||||||||||||
| 447 | cat->setEnabled(QtCriticalMsg, critical); | - | ||||||||||||||||||
| 448 | } executed 216993 times by 243 tests: end of blockExecuted by:
| 216993 | ||||||||||||||||||
| 449 | - | |||||||||||||||||||
| 450 | - | |||||||||||||||||||
| 451 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |