aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsloggingutils.cpp
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2024-10-22 14:54:08 +0200
committerSami Shalayel <sami.shalayel@qt.io>2024-10-29 13:00:19 +0100
commit282add1abf18171ea6d24777b928b900e672111d (patch)
tree16664f8c7e1b266685091c737a990ce1bc88b011 /src/qmlcompiler/qqmljsloggingutils.cpp
parent49eacf98d5e8857282735dc4356f20de8302908c (diff)
qmllint: allow plugins to set default category level
Add a defaultLevel value to the .json file shipped with the plugins that allow plugins to set the default level of their categories. Change-Id: I4a13366ce705ba104414b41e729d12769ab83821 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Diffstat (limited to 'src/qmlcompiler/qqmljsloggingutils.cpp')
-rw-r--r--src/qmlcompiler/qqmljsloggingutils.cpp31
1 files changed, 21 insertions, 10 deletions
diff --git a/src/qmlcompiler/qqmljsloggingutils.cpp b/src/qmlcompiler/qqmljsloggingutils.cpp
index 3b628d4438..168a003c36 100644
--- a/src/qmlcompiler/qqmljsloggingutils.cpp
+++ b/src/qmlcompiler/qqmljsloggingutils.cpp
@@ -154,6 +154,26 @@ QString levelToString(const QQmlJS::LoggerCategory &category)
}
};
+bool applyLevelToCategory(const QStringView level, LoggerCategory &category)
+{
+ if (level == "disable"_L1) {
+ category.setLevel(QtCriticalMsg);
+ category.setIgnored(true);
+ return true;
+ }
+ if (level == "info"_L1) {
+ category.setLevel(QtInfoMsg);
+ category.setIgnored(false);
+ return true;
+ }
+ if (level == "warning"_L1) {
+ category.setLevel(QtWarningMsg);
+ category.setIgnored(false);
+ return true;
+ }
+ return false;
+};
+
/*!
\internal
Sets the category levels from a settings file and an optional parser.
@@ -185,16 +205,7 @@ void updateLogLevels(QList<LoggerCategory> &categories,
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 {
+ if (!applyLevelToCategory(value, category)) {
qWarning() << "Invalid logging level" << value << "provided for"
<< category.id().name().toString()
<< "(allowed are: disable, info, warning)";