Exemplo n.º 1
0
/*!
    \internal
    Initializes the rules database by loading
    $QT_LOGGING_CONF, $QT_LOGGING_RULES, and .config/QtProject/qtlogging.ini.
 */
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)) {
            QTextStream stream(&file);
            QLoggingSettingsParser parser;
            parser.setContent(stream);
            if (qtLoggingDebug())
                debugMsg("Loading \"%s\" ...",
                         QDir::toNativeSeparators(file.fileName()).toUtf8().constData());
            envRules = parser.rules();
        }
    }
    const QByteArray rulesSrc = qgetenv("QT_LOGGING_RULES");
    if (!rulesSrc.isEmpty()) {
         QTextStream stream(rulesSrc);
         QLoggingSettingsParser parser;
         parser.setSection(QStringLiteral("Rules"));
         parser.setContent(stream);
         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)) {
            QTextStream stream(&file);
            QLoggingSettingsParser parser;
            parser.setContent(stream);
            if (qtLoggingDebug())
                debugMsg("Loading \"%s\" ...",
                         QDir::toNativeSeparators(envPath).toUtf8().constData());
            configRules = parser.rules();
        }
    }

    if (!envRules.isEmpty() || !configRules.isEmpty()) {
        QMutexLocker locker(&registryMutex);
        updateRules();
    }
}
Exemplo n.º 2
0
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>();
}
Exemplo n.º 3
0
/*!
    \internal
    Installs logging rules as specified in \a content.
 */
void QLoggingRegistry::setApiRules(const QString &content)
{
    QLoggingSettingsParser parser;
    parser.setSection(QStringLiteral("Rules"));
    parser.setContent(content);

    QMutexLocker locker(&registryMutex);

    if (qtLoggingDebug())
        debugMsg("Loading logging rules set by Qt API ...");

    apiRules = parser.rules();

    updateRules();
}
Exemplo n.º 4
0
/*!
    \internal
    Installs logging rules as specified in \a content.
 */
void QLoggingRegistry::setApiRules(const QString &content)
{
    QLoggingSettingsParser parser;
    parser.setImplicitRulesSection(true);
    parser.setContent(content);

    if (qtLoggingDebug())
        debugMsg("Loading logging rules set by QLoggingCategory::setFilterRules ...");

    const QMutexLocker locker(&registryMutex);

    ruleSets[ApiRules] = parser.rules();

    updateRules();
}