diff options
Diffstat (limited to 'src/corelib/io/qloggingregistry_p.h')
-rw-r--r-- | src/corelib/io/qloggingregistry_p.h | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/src/corelib/io/qloggingregistry_p.h b/src/corelib/io/qloggingregistry_p.h index b581af6c2f..92b96f0ba4 100644 --- a/src/corelib/io/qloggingregistry_p.h +++ b/src/corelib/io/qloggingregistry_p.h @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #ifndef QLOGGINGREGISTRY_P_H #define QLOGGINGREGISTRY_P_H @@ -54,21 +18,33 @@ #include <QtCore/private/qglobal_p.h> #include <QtCore/qloggingcategory.h> #include <QtCore/qlist.h> -#include <QtCore/qmap.h> +#include <QtCore/qhash.h> #include <QtCore/qmutex.h> #include <QtCore/qstring.h> #include <QtCore/qtextstream.h> +#include <map> + class tst_QLoggingRegistry; QT_BEGIN_NAMESPACE +#define Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(name, env, categoryName) \ + const QLoggingCategory &name() \ + { \ + static constexpr char cname[] = categoryName; \ + static_assert(cname[0] == 'q' && cname[1] == 't' && cname[2] == '.' \ + && cname[4] != '\0', "Category name must start with 'qt.'"); \ + static const QLoggingCategoryWithEnvironmentOverride category(cname, env); \ + return category; \ + } + class Q_AUTOTEST_EXPORT QLoggingRule { public: QLoggingRule(); QLoggingRule(QStringView pattern, bool enabled); - int pass(QLatin1String categoryName, QtMsgType type) const; + int pass(QLatin1StringView categoryName, QtMsgType type) const; enum PatternFlag { FullText = 0x1, @@ -79,23 +55,23 @@ public: Q_DECLARE_FLAGS(PatternFlags, PatternFlag) QString category; - int messageType; + int messageType = -1; PatternFlags flags; - bool enabled; + bool enabled = false; private: void parse(QStringView pattern); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QLoggingRule::PatternFlags) -Q_DECLARE_TYPEINFO(QLoggingRule, Q_MOVABLE_TYPE); +Q_DECLARE_TYPEINFO(QLoggingRule, Q_RELOCATABLE_TYPE); class Q_AUTOTEST_EXPORT QLoggingSettingsParser { public: void setImplicitRulesSection(bool inRulesSection) { m_inRulesSection = inRulesSection; } - void setContent(const QString &content); + void setContent(QStringView content); void setContent(QTextStream &stream); QList<QLoggingRule> rules() const { return _rules; } @@ -110,6 +86,7 @@ private: class Q_AUTOTEST_EXPORT QLoggingRegistry { + Q_DISABLE_COPY_MOVE(QLoggingRegistry) public: QLoggingRegistry(); @@ -118,6 +95,11 @@ public: void registerCategory(QLoggingCategory *category, QtMsgType enableForLevel); void unregisterCategory(QLoggingCategory *category); +#ifndef QT_BUILD_INTERNAL + Q_CORE_EXPORT // always export from QtCore +#endif + void registerEnvironmentOverrideForCategory(const char *categoryName, const char *environment); + void setApiRules(const QString &content); QLoggingCategory::CategoryFilter @@ -146,10 +128,28 @@ private: QList<QLoggingRule> ruleSets[NumRuleSets]; QHash<QLoggingCategory *, QtMsgType> categories; QLoggingCategory::CategoryFilter categoryFilter; + std::map<QByteArrayView, const char *> qtCategoryEnvironmentOverrides; friend class ::tst_QLoggingRegistry; }; +class QLoggingCategoryWithEnvironmentOverride : public QLoggingCategory +{ +public: + QLoggingCategoryWithEnvironmentOverride(const char *category, const char *env) + : QLoggingCategory(registerOverride(category, env), QtInfoMsg) + {} + +private: + static const char *registerOverride(const char *categoryName, const char *environment) + { + QLoggingRegistry *c = QLoggingRegistry::instance(); + if (c) + c->registerEnvironmentOverrideForCategory(categoryName, environment); + return categoryName; + } +}; + QT_END_NAMESPACE #endif // QLOGGINGREGISTRY_P_H |