blob: 1b08df8720793bf961dd1f1f3588d7048bd1c70c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
|
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "qqmljsloggingutils_p.h"
#include <QtQmlToolingSettings/private/qqmltoolingsettings_p.h>
#include <QtCore/qcommandlineparser.h>
QT_BEGIN_NAMESPACE
using namespace Qt::StringLiterals;
namespace QQmlJS {
LoggerCategory::LoggerCategory() : d_ptr{ new LoggerCategoryPrivate } { }
LoggerCategory::LoggerCategory(QString name, QString settingsName, QString description,
QtMsgType level, bool ignored, bool isDefault)
: d_ptr{ new LoggerCategoryPrivate }
{
Q_D(LoggerCategory);
d->m_name = name;
d->m_settingsName = settingsName;
d->m_description = description;
d->m_level = level;
d->m_ignored = ignored;
d->m_isDefault = isDefault;
}
LoggerCategory::LoggerCategory(const LoggerCategory &other)
: d_ptr{ new LoggerCategoryPrivate{ *other.d_func() } }
{
}
LoggerCategory::LoggerCategory(LoggerCategory &&) noexcept = default;
LoggerCategory &LoggerCategory::operator=(const LoggerCategory &other)
{
*d_func() = *other.d_func();
return *this;
}
LoggerCategory &LoggerCategory::operator=(LoggerCategory &&) noexcept = default;
LoggerCategory::~LoggerCategory() = default;
QString LoggerCategory::name() const
{
Q_D(const LoggerCategory);
return d->m_name;
}
QString LoggerCategory::settingsName() const
{
Q_D(const LoggerCategory);
return d->m_settingsName;
}
QString LoggerCategory::description() const
{
Q_D(const LoggerCategory);
return d->m_description;
}
QtMsgType LoggerCategory::level() const
{
Q_D(const LoggerCategory);
return d->m_level;
}
bool LoggerCategory::isIgnored() const
{
Q_D(const LoggerCategory);
return d->m_ignored;
}
bool LoggerCategory::isDefault() const
{
Q_D(const LoggerCategory);
return d->m_isDefault;
}
LoggerWarningId LoggerCategory::id() const
{
Q_D(const LoggerCategory);
return d->id();
}
void LoggerCategory::setLevel(QtMsgType type)
{
Q_D(LoggerCategory);
d->setLevel(type);
}
void LoggerCategoryPrivate::setLevel(QtMsgType type)
{
if (m_level == type)
return;
m_level = type;
m_changed = true;
}
void LoggerCategory::setIgnored(bool isIgnored)
{
Q_D(LoggerCategory);
d->setIgnored(isIgnored);
}
void LoggerCategoryPrivate::setIgnored(bool isIgnored)
{
if (m_ignored == isIgnored)
return;
m_ignored = isIgnored;
m_changed = true;
}
bool LoggerCategoryPrivate::hasChanged() const
{
return m_changed;
}
LoggerCategoryPrivate *LoggerCategoryPrivate::get(LoggerCategory *loggerCategory)
{
Q_ASSERT(loggerCategory);
return loggerCategory->d_func();
}
/*!
\class QQmlSA::LoggerWarningId
\inmodule QtQmlCompiler
\brief A wrapper around a string literal to uniquely identify
warning categories in the \c{QQmlSA} framework.
*/
/*!
\fn constexpr LoggerWarningId::LoggerWarningId(QAnyStringView name)
Constructs a LoggerWarningId object with logging catergory name \a name.
*/
/*!
\fn QAnyStringView LoggerWarningId::name() const
Returns the name of the wrapped warning category.
*/
namespace LoggingUtils {
QString levelToString(const QQmlJS::LoggerCategory &category)
{
Q_ASSERT(category.isIgnored() || category.level() != QtCriticalMsg);
if (category.isIgnored())
return QStringLiteral("disable");
switch (category.level()) {
case QtInfoMsg:
return QStringLiteral("info");
case QtWarningMsg:
return QStringLiteral("warning");
default:
Q_UNREACHABLE();
break;
}
};
/*!
\internal
Sets the category levels from a settings file and an optional parser.
Calls \c {parser->showHelp(-1)} for invalid logging levels.
*/
void updateLogLevels(QList<LoggerCategory> &categories,
const QQmlToolingSettings &settings,
QCommandLineParser *parser)
{
bool success = true;
for (auto &category : categories) {
if (category.isDefault())
continue;
const QString value = [&] () {
const QString key = category.id().name().toString();
if (parser && parser->isSet(key))
return parser->value(key);
// Do not try to set the levels if it's due to a default config option.
// This way we can tell which options have actually been overwritten by the user.
const QString settingsName = QStringLiteral("Warnings/") + category.settingsName();
const QString value = settings.value(settingsName).toString();
if (levelToString(category) == value)
return QString();
return value;
}();
if (value.isEmpty())
continue;
if (value == "disable"_L1) {
category.setLevel(QtCriticalMsg);
category.setIgnored(true);
} else if (value == "info"_L1) {
category.setLevel(QtInfoMsg);
category.setIgnored(false);
} else if (value == "warning"_L1) {
category.setLevel(QtWarningMsg);
category.setIgnored(false);
} else {
qWarning() << "Invalid logging level" << value << "provided for"
<< category.id().name().toString()
<< "(allowed are: disable, info, warning)";
success = false;
}
}
if (!success && parser)
parser->showHelp(-1);
}
} // namespace LoggingUtils
} // namespace QQmlJS
QT_END_NAMESPACE
|