Skip to content

Commit e730761

Browse files
committed
chore: replace qWarning with categorized logging
Replace all direct qWarning and qInfo calls with categorized logging macros (qCWarning, qCInfo) using appropriate logging categories (DNC, DSM). Add necessary includes for NetworkConst header where needed. Add .pragma library directive to NetUtils.js for better QML module handling. This change improves logging consistency and allows for better log filtering and management. Categorized logging provides more control over log output levels and destinations. The .pragma library directive ensures NetUtils.js functions are properly shared across QML components. Influence: 1. Verify that logging still works correctly in all modules 2. Test network operations to ensure no functional regressions 3. Check that QML components using NetUtils.js function properly 4. Verify log filtering capabilities with different log levels chore: 将 qWarning 替换为分类日志记录 将所有直接的 qWarning 和 qInfo 调用替换为使用适当日志分类(DNC、DSM)的 分类日志宏(qCWarning、qCInfo)。在需要的地方添加 NetworkConst 头文件包 含。为 NetUtils.js 添加 .pragma library 指令以改进 QML 模块处理。 此更改提高了日志记录的一致性,并允许更好的日志过滤和管理。分类日志记录提 供了对日志输出级别和目标的更多控制。.pragma library 指令确保 NetUtils.js 函数在 QML 组件之间正确共享。 Influence: 1. 验证所有模块中的日志记录是否仍然正常工作 2. 测试网络操作以确保没有功能回归 3. 检查使用 NetUtils.js 的 QML 组件是否正常运行 4. 使用不同日志级别验证日志过滤功能
1 parent a975448 commit e730761

File tree

8 files changed

+19
-22
lines changed

8 files changed

+19
-22
lines changed

dcc-network/operation/dccnetwork.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "dde-control-center/dccfactory.h"
77
#include "netitemmodel.h"
88
#include "netmanager.h"
9+
#include "networkconst.h"
910

1011
#include <NetworkManagerQt/GenericTypes>
1112

@@ -78,7 +79,7 @@ void DccNetwork::exec(NetManager::CmdType cmd, const QString &id, const QVariant
7879
dns.append(addr.toIPv4Address());
7980
} else if (addr.protocol() == QAbstractSocket::IPv6Protocol) {
8081
// IPv6地址转换为128位表示(当前系统可能不支持,先跳过)
81-
qWarning() << "IPv6 DNS not fully implemented in backend, DNS:" << dnsStr;
82+
qCWarning(DNC()) << "IPv6 DNS not fully implemented in backend, DNS:" << dnsStr;
8283
// 这里需要实现IPv6 DNS的完整支持
8384
}
8485
}
@@ -90,7 +91,7 @@ void DccNetwork::exec(NetManager::CmdType cmd, const QString &id, const QVariant
9091
}
9192
if (param.contains("ipv6")) {
9293
QVariantMap ipv6Data = param.value("ipv6").toMap();
93-
94+
9495
// 处理IPv6地址
9596
if (ipv6Data.contains("address-data")) {
9697
const QVariantList &addressData = ipv6Data.value("address-data").toList();
@@ -111,7 +112,7 @@ void DccNetwork::exec(NetManager::CmdType cmd, const QString &id, const QVariant
111112
}
112113
ipv6Data["addresses"] = QVariant::fromValue(ipv6AddressList);
113114
}
114-
115+
115116
// 处理IPv6 DNS
116117
if (ipv6Data.contains("dns")) {
117118
const QVariantList &dnsData = ipv6Data.value("dns").toList();
@@ -133,7 +134,7 @@ void DccNetwork::exec(NetManager::CmdType cmd, const QString &id, const QVariant
133134
for (const QHostAddress &addr : ipv6DnsAddresses) {
134135
ipv6DnsStrings.append(addr.toString());
135136
}
136-
137+
137138
// 使用字符串列表格式保存IPv6 DNS
138139
ipv6Data["dns"] = ipv6DnsStrings;
139140
ipv6Data["ignore-auto-dns"] = true;
@@ -143,13 +144,13 @@ void DccNetwork::exec(NetManager::CmdType cmd, const QString &id, const QVariant
143144
ipv6Data.remove("dns");
144145
ipv6Data.remove("ignore-auto-dns");
145146
}
146-
147+
147148
// 确保IPv6设置存在,即使没有DNS也要设置,以便被正确处理
148149
if (ipv6Data.isEmpty()) {
149-
ipv6Data["method"] = "auto"; // 至少设置一个值确保IPv6部分存在
150+
ipv6Data["method"] = "auto"; // 至少设置一个值确保IPv6部分存在
150151
}
151152
}
152-
153+
153154
tmpParam["ipv6"] = QVariant::fromValue(ipv6Data);
154155
}
155156
m_manager->exec(cmd, id, tmpParam);
@@ -170,7 +171,7 @@ bool DccNetwork::netCheckAvailable()
170171
if (!m_manager) {
171172
return false;
172173
}
173-
174+
174175
return m_manager->netCheckAvailable();
175176
}
176177

dcc-network/qml/NetUtils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
.pragma library
12
// SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd.
23
// SPDX-License-Identifier: GPL-3.0-or-later
34
const VpnTypeEnum = Object.freeze({

dss-network-plugin/networkmodule.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ QString NetworkPlugin::message(const QString &msgData)
290290
QJsonDocument json = QJsonDocument::fromJson(msgData.toLatin1());
291291
QJsonObject jsonObject = json.object();
292292
if (!jsonObject.contains("data")) {
293-
qWarning() << "msgData don't containt data" << msgData;
293+
qCWarning(DNC()) << "msgData don't containt data" << msgData;
294294
QJsonDocument jsonResult;
295295
QJsonObject resultObject;
296296
resultObject.insert("data", QString("msgData don't containt data %1").arg(msgData));
@@ -308,7 +308,7 @@ QString NetworkPlugin::message(const QString &msgData)
308308
QDBusPendingCall reply = dbusInter.asyncCall("UpdateLanguage", locale);
309309
reply.waitForFinished();
310310
} else {
311-
qWarning() << networkService << "don't start, wait for it start";
311+
qCWarning(DNC()) << networkService << "don't start, wait for it start";
312312
QDBusServiceWatcher *serviceWatcher = new QDBusServiceWatcher(this);
313313
serviceWatcher->setConnection(QDBusConnection::systemBus());
314314
serviceWatcher->addWatchedService(networkService);

dss-network-plugin/notification/bubblemanager.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,12 @@ void BubbleManager::CloseNotification(uint id)
4848
if (bubble->entity()->replacesId() == str_id) {
4949
bubble->close();
5050
m_bubbleList.removeOne(bubble);
51-
qDebug() << "CloseNotification : id" << str_id;
5251
}
5352
}
5453

5554
foreach (auto notify, m_oldEntities) {
5655
if (notify->replacesId() == str_id) {
5756
m_oldEntities.removeOne(notify);
58-
qDebug() << "CloseNotification : id" << str_id;
5957
}
6058
}
6159
}

network-service-plugin/src/system/networkinitialization.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ static QString getLocaleValue(const QString &filePath, const QStringList &keys,
403403
{
404404
QFile file(filePath);
405405
if (!file.open(QFile::ReadOnly | QFile::Text)) {
406-
qWarning() << "Failed to open locale file:" << filePath << "-" << file.errorString();
406+
qCWarning(DSM) << "Failed to open locale file:" << filePath << "-" << file.errorString();
407407
return QString();
408408
}
409409

network-service-plugin/src/utils/constants.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,14 @@ void dbusDebug(const QString &service, const QString &funName, const QDBusConnec
1616
msg << service;
1717
QDBusPendingReply<uint> reply = dbusConnection.asyncCall(msg);
1818
if (reply.isError()) {
19-
qWarning() << "API" << funName << "is called by" << service;
20-
qWarning() << funName << "error:" << reply.error();
19+
qCWarning(DSM) << "API" << funName << "is called by" << service << "error:" << reply.error();
2120
return;
2221
}
2322
uint pid = reply.value();
2423
QFile file(QString("/proc/%1/cmdline").arg(pid));
2524
if (file.open(QFile::ReadOnly)) {
2625
QByteArray cmd = file.readAll();
27-
qWarning() << "API" << funName << "is called by" << service << "(" << cmd.split('\0').join(" ") << ")";
26+
qCWarning(DSM) << "API" << funName << "is called by" << service << "(" << cmd.split('\0').join(" ") << ")";
2827
}
2928
}
3029
} // namespace service

src/dbus/proxychains.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// SPDX-License-Identifier: GPL-3.0-or-later
44

55
#include "proxychains.h"
6+
#include "networkconst.h"
67

78
/*
89
* Implementation of interface class __ProxyChains
@@ -112,7 +113,7 @@ void ProxyChains::onPropertyChanged(const QString &propName, const QVariant &val
112113
return;
113114
}
114115

115-
qWarning() << "On property changed,property not handle: " << propName;
116+
qCWarning(DNC()) << "On property changed,property not handle: " << propName;
116117
return;
117118
}
118119

src/networkcontroller.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
#include "wirelessdevice.h"
1919
#include "connectivityhandler.h"
2020

21-
#include <DLog>
22-
2321
// const static QString networkService = "org.deepin.dde.Network1";
2422
// const static QString networkPath = "/org/deepin/dde/Network1";
2523
static QString localeName;
@@ -42,7 +40,6 @@ NetworkController::NetworkController()
4240
, m_hotspotController(Q_NULLPTR)
4341
, m_connectivityHandler(new ConnectivityHandler(this))
4442
{
45-
Dtk::Core::loggerInstance()->setDefaultCategory(DNC().categoryName());
4643
retranslate(QLocale().name());
4744

4845
if (ConfigSetting::instance()->serviceFromNetworkManager()) {
@@ -152,9 +149,9 @@ void NetworkController::installTranslator(const QString &locale)
152149
}
153150
if (m_translator->load(QLocale(localeName), "dde-network-core", "_", "/usr/share/dde-network-core/translations")) {
154151
QCoreApplication::installTranslator(m_translator);
155-
qInfo() << "Loaded translation file for dde-network-core:" << m_translator->filePath();
152+
qCInfo(DNC()) << "Loaded translation file for dde-network-core:" << m_translator->filePath();
156153
} else {
157-
qWarning() << "Failed to load translation file for dde-network-core";
154+
qCWarning(DNC()) << "Failed to load translation file for dde-network-core";
158155
m_translator->deleteLater();
159156
m_translator = nullptr;
160157
}

0 commit comments

Comments
 (0)