| 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) 2016 The Qt Company Ltd. | - | ||||||||||||||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||||||||
| 5 | ** | - | ||||||||||||||||||
| 6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||||||||
| 7 | ** | - | ||||||||||||||||||
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||||||||
| 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 https://www.qt.io/terms-conditions. For further | - | ||||||||||||||||||
| 15 | ** information use the contact form at https://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 3 as published by the Free Software | - | ||||||||||||||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||||||||||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||||||||
| 24 | ** | - | ||||||||||||||||||
| 25 | ** GNU General Public License Usage | - | ||||||||||||||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||||||||
| 35 | ** | - | ||||||||||||||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||||||||||||||
| 37 | ** | - | ||||||||||||||||||
| 38 | ****************************************************************************/ | - | ||||||||||||||||||
| 39 | - | |||||||||||||||||||
| 40 | #include "qloggingregistry_p.h" | - | ||||||||||||||||||
| 41 | - | |||||||||||||||||||
| 42 | #include <QtCore/qfile.h> | - | ||||||||||||||||||
| 43 | #include <QtCore/qlibraryinfo.h> | - | ||||||||||||||||||
| 44 | #include <QtCore/qstandardpaths.h> | - | ||||||||||||||||||
| 45 | #include <QtCore/qtextstream.h> | - | ||||||||||||||||||
| 46 | #include <QtCore/qdir.h> | - | ||||||||||||||||||
| 47 | - | |||||||||||||||||||
| 48 | // We can't use the default macros because this would lead to recursion. | - | ||||||||||||||||||
| 49 | // Instead let's define our own one that unconditionally logs... | - | ||||||||||||||||||
| 50 | #define debugMsg QMessageLogger(__FILE__, __LINE__, __FUNCTION__, "qt.core.logging").debug | - | ||||||||||||||||||
| 51 | #define warnMsg QMessageLogger(__FILE__, __LINE__, __FUNCTION__, "qt.core.logging").warning | - | ||||||||||||||||||
| 52 | - | |||||||||||||||||||
| 53 | - | |||||||||||||||||||
| 54 | QT_BEGIN_NAMESPACE | - | ||||||||||||||||||
| 55 | - | |||||||||||||||||||
| 56 | Q_GLOBAL_STATIC(QLoggingRegistry, qtLoggingRegistry) | - | ||||||||||||||||||
| 57 | - | |||||||||||||||||||
| 58 | /*! | - | ||||||||||||||||||
| 59 | \internal | - | ||||||||||||||||||
| 60 | Constructs a logging rule with default values. | - | ||||||||||||||||||
| 61 | */ | - | ||||||||||||||||||
| 62 | QLoggingRule::QLoggingRule() : | - | ||||||||||||||||||
| 63 | enabled(false) | - | ||||||||||||||||||
| 64 | { | - | ||||||||||||||||||
| 65 | } | - | ||||||||||||||||||
| 66 | - | |||||||||||||||||||
| 67 | /*! | - | ||||||||||||||||||
| 68 | \internal | - | ||||||||||||||||||
| 69 | Constructs a logging rule. | - | ||||||||||||||||||
| 70 | */ | - | ||||||||||||||||||
| 71 | QLoggingRule::QLoggingRule(const QStringRef &pattern, bool enabled) : | - | ||||||||||||||||||
| 72 | messageType(-1), | - | ||||||||||||||||||
| 73 | enabled(enabled) | - | ||||||||||||||||||
| 74 | { | - | ||||||||||||||||||
| 75 | parse(pattern); | - | ||||||||||||||||||
| 76 | } | - | ||||||||||||||||||
| 77 | - | |||||||||||||||||||
| 78 | /*! | - | ||||||||||||||||||
| 79 | \internal | - | ||||||||||||||||||
| 80 | Return value 1 means filter passed, 0 means filter doesn't influence this | - | ||||||||||||||||||
| 81 | category, -1 means category doesn't pass this filter. | - | ||||||||||||||||||
| 82 | */ | - | ||||||||||||||||||
| 83 | int QLoggingRule::pass(const QString &cat, QtMsgType msgType) const | - | ||||||||||||||||||
| 84 | { | - | ||||||||||||||||||
| 85 | // check message type | - | ||||||||||||||||||
| 86 | if (messageType > -1 && messageType != msgType) | - | ||||||||||||||||||
| 87 | return 0; | - | ||||||||||||||||||
| 88 | - | |||||||||||||||||||
| 89 | if (flags == FullText) { | - | ||||||||||||||||||
| 90 | // full match | - | ||||||||||||||||||
| 91 | if (category == cat) | - | ||||||||||||||||||
| 92 | return (enabled ? 1 : -1); | - | ||||||||||||||||||
| 93 | else | - | ||||||||||||||||||
| 94 | return 0; | - | ||||||||||||||||||
| 95 | } | - | ||||||||||||||||||
| 96 | - | |||||||||||||||||||
| 97 | const int idx = cat.indexOf(category); | - | ||||||||||||||||||
| 98 | if (idx >= 0) { | - | ||||||||||||||||||
| 99 | if (flags == MidFilter) { | - | ||||||||||||||||||
| 100 | // matches somewhere | - | ||||||||||||||||||
| 101 | if (idx >= 0) | - | ||||||||||||||||||
| 102 | return (enabled ? 1 : -1); | - | ||||||||||||||||||
| 103 | } else if (flags == LeftFilter) { | - | ||||||||||||||||||
| 104 | // matches left | - | ||||||||||||||||||
| 105 | if (idx == 0) | - | ||||||||||||||||||
| 106 | return (enabled ? 1 : -1); | - | ||||||||||||||||||
| 107 | } else if (flags == RightFilter) { | - | ||||||||||||||||||
| 108 | // matches right | - | ||||||||||||||||||
| 109 | if (idx == (cat.count() - category.count())) | - | ||||||||||||||||||
| 110 | return (enabled ? 1 : -1); | - | ||||||||||||||||||
| 111 | } | - | ||||||||||||||||||
| 112 | } | - | ||||||||||||||||||
| 113 | return 0; | - | ||||||||||||||||||
| 114 | } | - | ||||||||||||||||||
| 115 | - | |||||||||||||||||||
| 116 | /*! | - | ||||||||||||||||||
| 117 | \internal | - | ||||||||||||||||||
| 118 | Parses \a pattern. | - | ||||||||||||||||||
| 119 | Allowed is f.ex.: | - | ||||||||||||||||||
| 120 | qt.core.io.debug FullText, QtDebugMsg | - | ||||||||||||||||||
| 121 | qt.core.* LeftFilter, all types | - | ||||||||||||||||||
| 122 | *.io.warning RightFilter, QtWarningMsg | - | ||||||||||||||||||
| 123 | *.core.* MidFilter | - | ||||||||||||||||||
| 124 | */ | - | ||||||||||||||||||
| 125 | void QLoggingRule::parse(const QStringRef &pattern) | - | ||||||||||||||||||
| 126 | { | - | ||||||||||||||||||
| 127 | QStringRef p; | - | ||||||||||||||||||
| 128 | - | |||||||||||||||||||
| 129 | // strip trailing ".messagetype" | - | ||||||||||||||||||
| 130 | if (pattern.endsWith(QLatin1String(".debug"))) { | - | ||||||||||||||||||
| 131 | p = QStringRef(pattern.string(), pattern.position(), | - | ||||||||||||||||||
| 132 | pattern.length() - 6); // strlen(".debug") | - | ||||||||||||||||||
| 133 | messageType = QtDebugMsg; | - | ||||||||||||||||||
| 134 | } else if (pattern.endsWith(QLatin1String(".info"))) { | - | ||||||||||||||||||
| 135 | p = QStringRef(pattern.string(), pattern.position(), | - | ||||||||||||||||||
| 136 | pattern.length() - 5); // strlen(".info") | - | ||||||||||||||||||
| 137 | messageType = QtInfoMsg; | - | ||||||||||||||||||
| 138 | } else if (pattern.endsWith(QLatin1String(".warning"))) { | - | ||||||||||||||||||
| 139 | p = QStringRef(pattern.string(), pattern.position(), | - | ||||||||||||||||||
| 140 | pattern.length() - 8); // strlen(".warning") | - | ||||||||||||||||||
| 141 | messageType = QtWarningMsg; | - | ||||||||||||||||||
| 142 | } else if (pattern.endsWith(QLatin1String(".critical"))) { | - | ||||||||||||||||||
| 143 | p = QStringRef(pattern.string(), pattern.position(), | - | ||||||||||||||||||
| 144 | pattern.length() - 9); // strlen(".critical") | - | ||||||||||||||||||
| 145 | messageType = QtCriticalMsg; | - | ||||||||||||||||||
| 146 | } else { | - | ||||||||||||||||||
| 147 | p = pattern; | - | ||||||||||||||||||
| 148 | } | - | ||||||||||||||||||
| 149 | - | |||||||||||||||||||
| 150 | if (!p.contains(QLatin1Char('*'))) { | - | ||||||||||||||||||
| 151 | flags = FullText; | - | ||||||||||||||||||
| 152 | } else { | - | ||||||||||||||||||
| 153 | if (p.endsWith(QLatin1Char('*'))) { | - | ||||||||||||||||||
| 154 | flags |= LeftFilter; | - | ||||||||||||||||||
| 155 | p = QStringRef(p.string(), p.position(), p.length() - 1); | - | ||||||||||||||||||
| 156 | } | - | ||||||||||||||||||
| 157 | if (p.startsWith(QLatin1Char('*'))) { | - | ||||||||||||||||||
| 158 | flags |= RightFilter; | - | ||||||||||||||||||
| 159 | p = QStringRef(p.string(), p.position() + 1, p.length() - 1); | - | ||||||||||||||||||
| 160 | } | - | ||||||||||||||||||
| 161 | if (p.contains(QLatin1Char('*'))) // '*' only supported at start/end | - | ||||||||||||||||||
| 162 | flags = 0; | - | ||||||||||||||||||
| 163 | } | - | ||||||||||||||||||
| 164 | - | |||||||||||||||||||
| 165 | category = p.toString(); | - | ||||||||||||||||||
| 166 | } | - | ||||||||||||||||||
| 167 | - | |||||||||||||||||||
| 168 | /*! | - | ||||||||||||||||||
| 169 | \class QLoggingSettingsParser | - | ||||||||||||||||||
| 170 | \since 5.3 | - | ||||||||||||||||||
| 171 | \internal | - | ||||||||||||||||||
| 172 | - | |||||||||||||||||||
| 173 | Parses a .ini file with the following format: | - | ||||||||||||||||||
| 174 | - | |||||||||||||||||||
| 175 | [rules] | - | ||||||||||||||||||
| 176 | rule1=[true|false] | - | ||||||||||||||||||
| 177 | rule2=[true|false] | - | ||||||||||||||||||
| 178 | ... | - | ||||||||||||||||||
| 179 | - | |||||||||||||||||||
| 180 | [rules] is the default section, and therefore optional. | - | ||||||||||||||||||
| 181 | */ | - | ||||||||||||||||||
| 182 | - | |||||||||||||||||||
| 183 | /*! | - | ||||||||||||||||||
| 184 | \internal | - | ||||||||||||||||||
| 185 | Parses configuration from \a content. | - | ||||||||||||||||||
| 186 | */ | - | ||||||||||||||||||
| 187 | void QLoggingSettingsParser::setContent(const QString &content) | - | ||||||||||||||||||
| 188 | { | - | ||||||||||||||||||
| 189 | QString content_ = content; | - | ||||||||||||||||||
| 190 | QTextStream stream(&content_, QIODevice::ReadOnly); | - | ||||||||||||||||||
| 191 | setContent(stream); | - | ||||||||||||||||||
| 192 | } | - | ||||||||||||||||||
| 193 | - | |||||||||||||||||||
| 194 | /*! | - | ||||||||||||||||||
| 195 | \internal | - | ||||||||||||||||||
| 196 | Parses configuration from \a stream. | - | ||||||||||||||||||
| 197 | */ | - | ||||||||||||||||||
| 198 | void QLoggingSettingsParser::setContent(QTextStream &stream) | - | ||||||||||||||||||
| 199 | { | - | ||||||||||||||||||
| 200 | _rules.clear(); | - | ||||||||||||||||||
| 201 | while (!stream.atEnd()) { | - | ||||||||||||||||||
| 202 | QString line = stream.readLine(); | - | ||||||||||||||||||
| 203 | - | |||||||||||||||||||
| 204 | // Remove all whitespace from line | - | ||||||||||||||||||
| 205 | line = line.simplified(); | - | ||||||||||||||||||
| 206 | line.remove(QLatin1Char(' ')); | - | ||||||||||||||||||
| 207 | - | |||||||||||||||||||
| 208 | // comment | - | ||||||||||||||||||
| 209 | if (line.startsWith(QLatin1Char(';'))) | - | ||||||||||||||||||
| 210 | continue; | - | ||||||||||||||||||
| 211 | - | |||||||||||||||||||
| 212 | if (line.startsWith(QLatin1Char('[')) && line.endsWith(QLatin1Char(']'))) { | - | ||||||||||||||||||
| 213 | // new section | - | ||||||||||||||||||
| 214 | _section = line.mid(1, line.size() - 2); | - | ||||||||||||||||||
| 215 | continue; | - | ||||||||||||||||||
| 216 | } | - | ||||||||||||||||||
| 217 | - | |||||||||||||||||||
| 218 | if (_section.toLower() == QLatin1String("rules")) { | - | ||||||||||||||||||
| 219 | int equalPos = line.indexOf(QLatin1Char('=')); | - | ||||||||||||||||||
| 220 | if (equalPos != -1) { | - | ||||||||||||||||||
| 221 | if (line.lastIndexOf(QLatin1Char('=')) == equalPos) { | - | ||||||||||||||||||
| 222 | const QStringRef pattern = line.leftRef(equalPos); | - | ||||||||||||||||||
| 223 | const QStringRef valueStr = line.midRef(equalPos + 1); | - | ||||||||||||||||||
| 224 | int value = -1; | - | ||||||||||||||||||
| 225 | if (valueStr == QLatin1String("true")) | - | ||||||||||||||||||
| 226 | value = 1; | - | ||||||||||||||||||
| 227 | else if (valueStr == QLatin1String("false")) | - | ||||||||||||||||||
| 228 | value = 0; | - | ||||||||||||||||||
| 229 | QLoggingRule rule(pattern, (value == 1)); | - | ||||||||||||||||||
| 230 | if (rule.flags != 0 && (value != -1)) | - | ||||||||||||||||||
| 231 | _rules.append(rule); | - | ||||||||||||||||||
| 232 | else | - | ||||||||||||||||||
| 233 | warnMsg("Ignoring malformed logging rule: '%s'", line.toUtf8().constData()); | - | ||||||||||||||||||
| 234 | } else { | - | ||||||||||||||||||
| 235 | warnMsg("Ignoring malformed logging rule: '%s'", line.toUtf8().constData()); | - | ||||||||||||||||||
| 236 | } | - | ||||||||||||||||||
| 237 | } | - | ||||||||||||||||||
| 238 | } | - | ||||||||||||||||||
| 239 | } | - | ||||||||||||||||||
| 240 | } | - | ||||||||||||||||||
| 241 | - | |||||||||||||||||||
| 242 | /*! | - | ||||||||||||||||||
| 243 | \internal | - | ||||||||||||||||||
| 244 | QLoggingRegistry constructor | - | ||||||||||||||||||
| 245 | */ | - | ||||||||||||||||||
| 246 | QLoggingRegistry::QLoggingRegistry() | - | ||||||||||||||||||
| 247 | : categoryFilter(defaultCategoryFilter) | - | ||||||||||||||||||
| 248 | { | - | ||||||||||||||||||
| 249 | } | - | ||||||||||||||||||
| 250 | - | |||||||||||||||||||
| 251 | static bool qtLoggingDebug() | - | ||||||||||||||||||
| 252 | { | - | ||||||||||||||||||
| 253 | static const bool debugEnv = qEnvironmentVariableIsSet("QT_LOGGING_DEBUG"); | - | ||||||||||||||||||
| 254 | return debugEnv; | - | ||||||||||||||||||
| 255 | } | - | ||||||||||||||||||
| 256 | - | |||||||||||||||||||
| 257 | static QVector<QLoggingRule> loadRulesFromFile(const QString &filePath) | - | ||||||||||||||||||
| 258 | { | - | ||||||||||||||||||
| 259 | QFile file(filePath); | - | ||||||||||||||||||
| 260 | if (file.open(QIODevice::ReadOnly | QIODevice::Text)) { | - | ||||||||||||||||||
| 261 | if (qtLoggingDebug()) | - | ||||||||||||||||||
| 262 | debugMsg("Loading \"%s\" ...", | - | ||||||||||||||||||
| 263 | QDir::toNativeSeparators(file.fileName()).toUtf8().constData()); | - | ||||||||||||||||||
| 264 | QTextStream stream(&file); | - | ||||||||||||||||||
| 265 | QLoggingSettingsParser parser; | - | ||||||||||||||||||
| 266 | parser.setContent(stream); | - | ||||||||||||||||||
| 267 | return parser.rules(); | - | ||||||||||||||||||
| 268 | } | - | ||||||||||||||||||
| 269 | return QVector<QLoggingRule>(); | - | ||||||||||||||||||
| 270 | } | - | ||||||||||||||||||
| 271 | - | |||||||||||||||||||
| 272 | /*! | - | ||||||||||||||||||
| 273 | \internal | - | ||||||||||||||||||
| 274 | Initializes the rules database by loading | - | ||||||||||||||||||
| 275 | $QT_LOGGING_CONF, $QT_LOGGING_RULES, and .config/QtProject/qtlogging.ini. | - | ||||||||||||||||||
| 276 | */ | - | ||||||||||||||||||
| 277 | void QLoggingRegistry::init() | - | ||||||||||||||||||
| 278 | { | - | ||||||||||||||||||
| 279 | QVector<QLoggingRule> er, qr, cr;// get rules from environment | - | ||||||||||||||||||
| 280 | const QByteArray rulesFilePath = qgetenv("QT_LOGGING_CONF"); | - | ||||||||||||||||||
| 281 | if (!rulesFilePath.isEmpty())
| 3-1078 | ||||||||||||||||||
| 282 | erenvRules = loadRulesFromFile(QFile::decodeName(rulesFilePath)); executed 3 times by 1 test: envRules = loadRulesFromFile(QFile::decodeName(rulesFilePath));Executed by:
| 3 | ||||||||||||||||||
| 283 | - | |||||||||||||||||||
| 284 | const QByteArray rulesSrc = qgetenv("QT_LOGGING_RULES").replace(';', '\n'); | - | ||||||||||||||||||
| 285 | if (!rulesSrc.isEmpty()) {
| 2-1079 | ||||||||||||||||||
| 286 | QTextStream stream(rulesSrc); | - | ||||||||||||||||||
| 287 | QLoggingSettingsParser parser; | - | ||||||||||||||||||
| 288 | parser.setSection(QStringLiteral("Rules")); | - | ||||||||||||||||||
| 289 | parser.setContent(stream); | - | ||||||||||||||||||
| 290 | erenvRules += parser.rules(); | - | ||||||||||||||||||
| 291 | } executed 2 times by 1 test: end of blockExecuted by:
| 2 | ||||||||||||||||||
| 292 | - | |||||||||||||||||||
| 293 | const QString configFileName = QStringLiteral("qtlogging.ini"); executed 1081 times by 24 tests: return qstring_literal_temp;Executed by:
| 1081 | ||||||||||||||||||
| 294 | - | |||||||||||||||||||
| 295 | #if !defined(QT_BOOTSTRAPPED) | - | ||||||||||||||||||
| 296 | // get rules from Qt data configuration path | - | ||||||||||||||||||
| 297 | const QString qtConfigPath | - | ||||||||||||||||||
| 298 | = QDir(QLibraryInfo::location(QLibraryInfo::DataPath)).absoluteFilePath(configFileName); | - | ||||||||||||||||||
| 299 | qrqtConfigRules = loadRulesFromFile(qtConfigPath); | - | ||||||||||||||||||
| 300 | #endif | - | ||||||||||||||||||
| 301 | - | |||||||||||||||||||
| 302 | // get rules from user's/system configuration | - | ||||||||||||||||||
| 303 | const QString envPath = QStandardPaths::locate(QStandardPaths::GenericConfigLocation, | - | ||||||||||||||||||
| 304 | QString::fromLatin1("QtProject/") + configFileName); | - | ||||||||||||||||||
| 305 | if (!envPath.isEmpty())
| 1-1079 | ||||||||||||||||||
| 306 | crconfigRules = loadRulesFromFile(envPath); executed 1 time by 1 test: configRules = loadRulesFromFile(envPath);Executed by:
| 1 | ||||||||||||||||||
| const QMutexLocker locker(®istryMutex); executed 1 time by 1 test: configRules = loadRulesFromFile(envPath);Executed by:
| ||||||||||||||||||||
| envRules = qMove(er); executed 1 time by 1 test: configRules = loadRulesFromFile(envPath);Executed by:
| ||||||||||||||||||||
| qtConfigRules = qMove(qr); executed 1 time by 1 test: configRules = loadRulesFromFile(envPath);Executed by:
| ||||||||||||||||||||
| configRules = qMove(cr executed 1 time by 1 test: );configRules = loadRulesFromFile(envPath);Executed by:
executed 1 time by 1 test: configRules = loadRulesFromFile(envPath);Executed by:
| ||||||||||||||||||||
| 307 | - | |||||||||||||||||||
| 308 | if (!envRules.isEmpty() || !qtConfigRules.isEmpty() || !configRules.isEmpty()) {
| 0-1077 | ||||||||||||||||||
| 309 | QMutexLocker locker(®istryMutex); | - | ||||||||||||||||||
| 310 | updateRules(); | - | ||||||||||||||||||
| 311 | } executed 3 times by 1 test: end of blockExecuted by:
| 3 | ||||||||||||||||||
| 312 | } executed 1080 times by 24 tests: end of blockExecuted by:
| 1080 | ||||||||||||||||||
| 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)) { | - | ||||||||||||||||||
| 325 | categories.insert(cat, enableForLevel); | - | ||||||||||||||||||
| 326 | (*categoryFilter)(cat); | - | ||||||||||||||||||
| 327 | } | - | ||||||||||||||||||
| 328 | } | - | ||||||||||||||||||
| 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 | } | - | ||||||||||||||||||
| 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")); | - | ||||||||||||||||||
| 348 | parser.setContent(content); | - | ||||||||||||||||||
| 349 | - | |||||||||||||||||||
| 350 | QMutexLocker locker(®istryMutex); | - | ||||||||||||||||||
| 351 | - | |||||||||||||||||||
| 352 | if (qtLoggingDebug())
| 0-24019 | ||||||||||||||||||
| 353 | debugMsg("Loading logging rules set by QLoggingCategory::setFilterRules ..."); never executed: QMessageLogger(__FILE__, 353, __FUNCTION__, "qt.core.logging").debug("Loading logging rules set by QLoggingCategory::setFilterRules ..."); | 0 | ||||||||||||||||||
| const QMutexLocker locker(®istryMutex never executed: );QMessageLogger(__FILE__, 353, __FUNCTION__, "qt.core.logging").debug("Loading logging rules set by QLoggingCategory::setFilterRules ...");never executed: QMessageLogger(__FILE__, 353, __FUNCTION__, "qt.core.logging").debug("Loading logging rules set by QLoggingCategory::setFilterRules ..."); | ||||||||||||||||||||
| 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 | foreachfor (QLoggingCategory *cat,auto it = categories.keys())keyBegin(), end = categories.keyEnd(); it != end; ++it)
| 24025-216136 | ||||||||||||||||||
| 371 | (*categoryFilter)(cat)(*it); executed 216136 times by 2 tests: (*categoryFilter)(*it);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 | foreachfor (QLoggingCategory *cat,auto it = categories.keys())keyBegin(), end = categories.keyEnd(); it != end; ++it)
| 7-22 | ||||||||||||||||||
| 390 | (*categoryFilter)(cat)(*it); executed 22 times by 1 test: (*categoryFilter)(*it);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(); | - | ||||||||||||||||||
| 398 | } | - | ||||||||||||||||||
| 399 | - | |||||||||||||||||||
| 400 | /*! | - | ||||||||||||||||||
| 401 | \internal | - | ||||||||||||||||||
| 402 | Updates category settings according to rules. | - | ||||||||||||||||||
| 403 | */ | - | ||||||||||||||||||
| 404 | void QLoggingRegistry::defaultCategoryFilter(QLoggingCategory *cat) | - | ||||||||||||||||||
| 405 | { | - | ||||||||||||||||||
| 406 | const QLoggingRegistry *reg = QLoggingRegistry::instance(); | - | ||||||||||||||||||
| 407 | Q_ASSERT(reg->categories.contains(cat)); | - | ||||||||||||||||||
| 408 | QtMsgType enableForLevel = reg->categories.value(cat); | - | ||||||||||||||||||
| 409 | - | |||||||||||||||||||
| 410 | // NB: note that the numeric values of the Qt*Msg constants are | - | ||||||||||||||||||
| 411 | // not in severity order. | - | ||||||||||||||||||
| 412 | bool debug = (enableForLevel == QtDebugMsg); | - | ||||||||||||||||||
| 413 | bool info = debug || (enableForLevel == QtInfoMsg);
| 24020-169024 | ||||||||||||||||||
| 414 | bool warning = info || (enableForLevel == QtWarningMsg);
| 1-193044 | ||||||||||||||||||
| 415 | bool critical = warning || (enableForLevel == QtCriticalMsg);
| 0-193045 | ||||||||||||||||||
| 416 | - | |||||||||||||||||||
| 417 | // hard-wired implementation of | - | ||||||||||||||||||
| 418 | // qt.*.debug=false | - | ||||||||||||||||||
| 419 | // qt.debug=false | - | ||||||||||||||||||
| 420 | if (const char *categoryName = cat->categoryName()) {
| 0-217065 | ||||||||||||||||||
| 421 | // == "qt" or startsWith("qt.") | - | ||||||||||||||||||
| 422 | if (strcmp(categoryName, "qt") == 0 || strncmp(categoryName, "qt.", 3) == 0)
| 0-217065 | ||||||||||||||||||
| 423 | debug = false; executed 379 times by 137 tests: debug = false;Executed by:
| 379 | ||||||||||||||||||
| 424 | } executed 217065 times by 243 tests: end of blockExecuted by:
| 217065 | ||||||||||||||||||
| 425 | - | |||||||||||||||||||
| 426 | QString categoryName = QLatin1String(cat->categoryName()); | - | ||||||||||||||||||
| 427 | foreachfor (const QLoggingRule &item ,: reg->rules) { | - | ||||||||||||||||||
| 428 | int filterpass = item.pass(categoryName, QtDebugMsg); | - | ||||||||||||||||||
| 429 | if (filterpass != 0)
| 72079-144381 | ||||||||||||||||||
| 430 | debug = (filterpass > 0); executed 72079 times by 2 tests: debug = (filterpass > 0);Executed by:
| 72079 | ||||||||||||||||||
| 431 | filterpass = item.pass(categoryName, QtInfoMsg); | - | ||||||||||||||||||
| 432 | if (filterpass != 0)
| 72067-144393 | ||||||||||||||||||
| 433 | info = (filterpass > 0); executed 72067 times by 2 tests: info = (filterpass > 0);Executed by:
| 72067 | ||||||||||||||||||
| 434 | filterpass = item.pass(categoryName, QtWarningMsg); | - | ||||||||||||||||||
| 435 | if (filterpass != 0)
| 72067-144393 | ||||||||||||||||||
| 436 | warning = (filterpass > 0); executed 72067 times by 2 tests: warning = (filterpass > 0);Executed by:
| 72067 | ||||||||||||||||||
| 437 | filterpass = item.pass(categoryName, QtCriticalMsg); | - | ||||||||||||||||||
| 438 | if (filterpass != 0)
| 72066-144394 | ||||||||||||||||||
| 439 | critical = (filterpass > 0); executed 72066 times by 2 tests: critical = (filterpass > 0);Executed by:
| 72066 | ||||||||||||||||||
| 440 | } executed 216460 times by 2 tests: end of blockExecuted by:
| 216460 | ||||||||||||||||||
| 441 | - | |||||||||||||||||||
| 442 | cat->setEnabled(QtDebugMsg, debug); | - | ||||||||||||||||||
| 443 | cat->setEnabled(QtInfoMsg, info); | - | ||||||||||||||||||
| 444 | cat->setEnabled(QtWarningMsg, warning); | - | ||||||||||||||||||
| 445 | cat->setEnabled(QtCriticalMsg, critical); | - | ||||||||||||||||||
| 446 | } executed 217065 times by 243 tests: end of blockExecuted by:
| 217065 | ||||||||||||||||||
| 447 | - | |||||||||||||||||||
| 448 | - | |||||||||||||||||||
| 449 | QT_END_NAMESPACE | - | ||||||||||||||||||
| Source code | Switch to Preprocessed file |