Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qloggingregistry_p.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QLOGGINGREGISTRY_P_H
5#define QLOGGINGREGISTRY_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists for the convenience
12// of a number of Qt sources files. This header file may change from
13// version to version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/private/qglobal_p.h>
19#include <QtCore/qloggingcategory.h>
20#include <QtCore/qlist.h>
21#include <QtCore/qhash.h>
22#include <QtCore/qmutex.h>
23#include <QtCore/qstring.h>
24#include <QtCore/qtextstream.h>
25
26#include <map>
27
28class tst_QLoggingRegistry;
29
31
32#define Q_LOGGING_CATEGORY_WITH_ENV_OVERRIDE(name, env, categoryName) \
33 const QLoggingCategory &name() \
34 { \
35 static constexpr char cname[] = categoryName; \
36 static_assert(cname[0] == 'q' && cname[1] == 't' && cname[2] == '.' \
37 && cname[4] != '\0', "Category name must start with 'qt.'"); \
38 static const QLoggingCategoryWithEnvironmentOverride category(cname, env); \
39 return category; \
40 }
41
43{
44public:
47 int pass(QLatin1StringView categoryName, QtMsgType type) const;
48
50 FullText = 0x1,
51 LeftFilter = 0x2,
52 RightFilter = 0x4,
53 MidFilter = LeftFilter | RightFilter
54 };
55 Q_DECLARE_FLAGS(PatternFlags, PatternFlag)
56
58 int messageType = -1;
59 PatternFlags flags;
60 bool enabled = false;
61
63 void parse(QStringView pattern);
64};
65
68
70{
71public:
72 void setImplicitRulesSection(bool inRulesSection) { m_inRulesSection = inRulesSection; }
73
74 void setContent(QStringView content);
75 void setContent(QTextStream &stream);
76
77 QList<QLoggingRule> rules() const { return _rules; }
78
79private:
80 void parseNextLine(QStringView line);
81
82private:
83 bool m_inRulesSection = false;
84 QList<QLoggingRule> _rules;
85};
86
88{
89 Q_DISABLE_COPY_MOVE(QLoggingRegistry)
90public:
92
93 void initializeRules();
94
95 void registerCategory(QLoggingCategory *category, QtMsgType enableForLevel);
96 void unregisterCategory(QLoggingCategory *category);
97
98#ifndef QT_BUILD_INTERNAL
99 Q_CORE_EXPORT // always export from QtCore
100#endif
101 void registerEnvironmentOverrideForCategory(const char *categoryName, const char *environment);
102
103 void setApiRules(const QString &content);
104
107
108 static QLoggingRegistry *instance();
109
110private:
111 void updateRules();
112
113 static void defaultCategoryFilter(QLoggingCategory *category);
114
115 enum RuleSet {
116 // sorted by order in which defaultCategoryFilter considers them:
117 QtConfigRules,
118 ConfigRules,
119 ApiRules,
120 EnvironmentRules,
121
122 NumRuleSets
123 };
124
125 QMutex registryMutex;
126
127 // protected by mutex:
128 QList<QLoggingRule> ruleSets[NumRuleSets];
129 QHash<QLoggingCategory *, QtMsgType> categories;
131 std::map<QByteArrayView, const char *> qtCategoryEnvironmentOverrides;
132
133 friend class ::tst_QLoggingRegistry;
134};
135
137{
138public:
140 : QLoggingCategory(registerOverride(category, env), QtInfoMsg)
141 {}
142
143private:
144 static const char *registerOverride(const char *categoryName, const char *environment)
145 {
147 if (c)
148 c->registerEnvironmentOverrideForCategory(categoryName, environment);
149 return categoryName;
150 }
151};
152
154
155#endif // QLOGGINGREGISTRY_P_H
QLoggingCategoryWithEnvironmentOverride(const char *category, const char *env)
\inmodule QtCore
void(* CategoryFilter)(QLoggingCategory *)
This is a typedef for a pointer to a function with the following signature:
static QLoggingRegistry * instance()
void setImplicitRulesSection(bool inRulesSection)
QList< QLoggingRule > rules() const
\inmodule QtCore
Definition qmutex.h:281
\inmodule QtCore
Definition qstringview.h:78
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
\inmodule QtCore
const QLoggingCategory & category()
[1]
Combined button and popup list for selecting options.
EGLStreamKHR stream
#define Q_DECLARE_FLAGS(Flags, Enum)
Definition qflags.h:174
#define Q_DECLARE_OPERATORS_FOR_FLAGS(Flags)
Definition qflags.h:194
QtMsgType
Definition qlogging.h:29
@ QtInfoMsg
Definition qlogging.h:34
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLenum type
GLbitfield flags
GLint GLint GLint GLint GLint GLint GLint GLbitfield GLenum filter
GLsizei GLenum * categories
const GLubyte * c
GLubyte * pattern
#define Q_AUTOTEST_EXPORT
@ Q_RELOCATABLE_TYPE
Definition qtypeinfo.h:158
#define Q_DECLARE_TYPEINFO(TYPE, FLAGS)
Definition qtypeinfo.h:180