From 65852859bfa8a8ed6663785fd453a94c8a611d08 Mon Sep 17 00:00:00 2001 From: caixiangrong Date: Wed, 14 Jan 2026 16:35:06 +0800 Subject: [PATCH] chore: replace qWarning with categorized logging MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. 使用不同日志级别验证日志过滤功能 --- dcc-network/operation/dccnetwork.cpp | 17 +++++++++-------- dcc-network/qml/NetUtils.js | 1 + dss-network-plugin/networkmodule.cpp | 4 ++-- .../notification/bubblemanager.cpp | 2 -- .../src/system/networkinitialization.cpp | 2 +- network-service-plugin/src/utils/constants.cpp | 5 ++--- src/dbus/proxychains.cpp | 3 ++- src/networkcontroller.cpp | 7 ++----- 8 files changed, 19 insertions(+), 22 deletions(-) diff --git a/dcc-network/operation/dccnetwork.cpp b/dcc-network/operation/dccnetwork.cpp index 217226fb..644a1cf3 100644 --- a/dcc-network/operation/dccnetwork.cpp +++ b/dcc-network/operation/dccnetwork.cpp @@ -6,6 +6,7 @@ #include "dde-control-center/dccfactory.h" #include "netitemmodel.h" #include "netmanager.h" +#include "networkconst.h" #include @@ -78,7 +79,7 @@ void DccNetwork::exec(NetManager::CmdType cmd, const QString &id, const QVariant dns.append(addr.toIPv4Address()); } else if (addr.protocol() == QAbstractSocket::IPv6Protocol) { // IPv6地址转换为128位表示(当前系统可能不支持,先跳过) - qWarning() << "IPv6 DNS not fully implemented in backend, DNS:" << dnsStr; + qCWarning(DNC()) << "IPv6 DNS not fully implemented in backend, DNS:" << dnsStr; // 这里需要实现IPv6 DNS的完整支持 } } @@ -90,7 +91,7 @@ void DccNetwork::exec(NetManager::CmdType cmd, const QString &id, const QVariant } if (param.contains("ipv6")) { QVariantMap ipv6Data = param.value("ipv6").toMap(); - + // 处理IPv6地址 if (ipv6Data.contains("address-data")) { const QVariantList &addressData = ipv6Data.value("address-data").toList(); @@ -111,7 +112,7 @@ void DccNetwork::exec(NetManager::CmdType cmd, const QString &id, const QVariant } ipv6Data["addresses"] = QVariant::fromValue(ipv6AddressList); } - + // 处理IPv6 DNS if (ipv6Data.contains("dns")) { const QVariantList &dnsData = ipv6Data.value("dns").toList(); @@ -133,7 +134,7 @@ void DccNetwork::exec(NetManager::CmdType cmd, const QString &id, const QVariant for (const QHostAddress &addr : ipv6DnsAddresses) { ipv6DnsStrings.append(addr.toString()); } - + // 使用字符串列表格式保存IPv6 DNS ipv6Data["dns"] = ipv6DnsStrings; ipv6Data["ignore-auto-dns"] = true; @@ -143,13 +144,13 @@ void DccNetwork::exec(NetManager::CmdType cmd, const QString &id, const QVariant ipv6Data.remove("dns"); ipv6Data.remove("ignore-auto-dns"); } - + // 确保IPv6设置存在,即使没有DNS也要设置,以便被正确处理 if (ipv6Data.isEmpty()) { - ipv6Data["method"] = "auto"; // 至少设置一个值确保IPv6部分存在 + ipv6Data["method"] = "auto"; // 至少设置一个值确保IPv6部分存在 } } - + tmpParam["ipv6"] = QVariant::fromValue(ipv6Data); } m_manager->exec(cmd, id, tmpParam); @@ -170,7 +171,7 @@ bool DccNetwork::netCheckAvailable() if (!m_manager) { return false; } - + return m_manager->netCheckAvailable(); } diff --git a/dcc-network/qml/NetUtils.js b/dcc-network/qml/NetUtils.js index 3a362e24..ac45fcb6 100644 --- a/dcc-network/qml/NetUtils.js +++ b/dcc-network/qml/NetUtils.js @@ -1,3 +1,4 @@ +.pragma library // SPDX-FileCopyrightText: 2024 - 2027 UnionTech Software Technology Co., Ltd. // SPDX-License-Identifier: GPL-3.0-or-later const VpnTypeEnum = Object.freeze({ diff --git a/dss-network-plugin/networkmodule.cpp b/dss-network-plugin/networkmodule.cpp index e8f64c4e..2817b1ea 100644 --- a/dss-network-plugin/networkmodule.cpp +++ b/dss-network-plugin/networkmodule.cpp @@ -290,7 +290,7 @@ QString NetworkPlugin::message(const QString &msgData) QJsonDocument json = QJsonDocument::fromJson(msgData.toLatin1()); QJsonObject jsonObject = json.object(); if (!jsonObject.contains("data")) { - qWarning() << "msgData don't containt data" << msgData; + qCWarning(DNC()) << "msgData don't containt data" << msgData; QJsonDocument jsonResult; QJsonObject resultObject; resultObject.insert("data", QString("msgData don't containt data %1").arg(msgData)); @@ -308,7 +308,7 @@ QString NetworkPlugin::message(const QString &msgData) QDBusPendingCall reply = dbusInter.asyncCall("UpdateLanguage", locale); reply.waitForFinished(); } else { - qWarning() << networkService << "don't start, wait for it start"; + qCWarning(DNC()) << networkService << "don't start, wait for it start"; QDBusServiceWatcher *serviceWatcher = new QDBusServiceWatcher(this); serviceWatcher->setConnection(QDBusConnection::systemBus()); serviceWatcher->addWatchedService(networkService); diff --git a/dss-network-plugin/notification/bubblemanager.cpp b/dss-network-plugin/notification/bubblemanager.cpp index 76d0ccfa..272cd0ec 100644 --- a/dss-network-plugin/notification/bubblemanager.cpp +++ b/dss-network-plugin/notification/bubblemanager.cpp @@ -48,14 +48,12 @@ void BubbleManager::CloseNotification(uint id) if (bubble->entity()->replacesId() == str_id) { bubble->close(); m_bubbleList.removeOne(bubble); - qDebug() << "CloseNotification : id" << str_id; } } foreach (auto notify, m_oldEntities) { if (notify->replacesId() == str_id) { m_oldEntities.removeOne(notify); - qDebug() << "CloseNotification : id" << str_id; } } } diff --git a/network-service-plugin/src/system/networkinitialization.cpp b/network-service-plugin/src/system/networkinitialization.cpp index 6426c4cb..57265b96 100755 --- a/network-service-plugin/src/system/networkinitialization.cpp +++ b/network-service-plugin/src/system/networkinitialization.cpp @@ -403,7 +403,7 @@ static QString getLocaleValue(const QString &filePath, const QStringList &keys, { QFile file(filePath); if (!file.open(QFile::ReadOnly | QFile::Text)) { - qWarning() << "Failed to open locale file:" << filePath << "-" << file.errorString(); + qCWarning(DSM) << "Failed to open locale file:" << filePath << "-" << file.errorString(); return QString(); } diff --git a/network-service-plugin/src/utils/constants.cpp b/network-service-plugin/src/utils/constants.cpp index 8c4e92a8..23a8cdac 100644 --- a/network-service-plugin/src/utils/constants.cpp +++ b/network-service-plugin/src/utils/constants.cpp @@ -16,15 +16,14 @@ void dbusDebug(const QString &service, const QString &funName, const QDBusConnec msg << service; QDBusPendingReply reply = dbusConnection.asyncCall(msg); if (reply.isError()) { - qWarning() << "API" << funName << "is called by" << service; - qWarning() << funName << "error:" << reply.error(); + qCWarning(DSM) << "API" << funName << "is called by" << service << "error:" << reply.error(); return; } uint pid = reply.value(); QFile file(QString("/proc/%1/cmdline").arg(pid)); if (file.open(QFile::ReadOnly)) { QByteArray cmd = file.readAll(); - qWarning() << "API" << funName << "is called by" << service << "(" << cmd.split('\0').join(" ") << ")"; + qCWarning(DSM) << "API" << funName << "is called by" << service << "(" << cmd.split('\0').join(" ") << ")"; } } } // namespace service diff --git a/src/dbus/proxychains.cpp b/src/dbus/proxychains.cpp index abb5215c..5d87e603 100644 --- a/src/dbus/proxychains.cpp +++ b/src/dbus/proxychains.cpp @@ -3,6 +3,7 @@ // SPDX-License-Identifier: GPL-3.0-or-later #include "proxychains.h" +#include "networkconst.h" /* * Implementation of interface class __ProxyChains @@ -112,7 +113,7 @@ void ProxyChains::onPropertyChanged(const QString &propName, const QVariant &val return; } - qWarning() << "On property changed,property not handle: " << propName; + qCWarning(DNC()) << "On property changed,property not handle: " << propName; return; } diff --git a/src/networkcontroller.cpp b/src/networkcontroller.cpp index 2f072eb1..f8c3a899 100644 --- a/src/networkcontroller.cpp +++ b/src/networkcontroller.cpp @@ -18,8 +18,6 @@ #include "wirelessdevice.h" #include "connectivityhandler.h" -#include - // const static QString networkService = "org.deepin.dde.Network1"; // const static QString networkPath = "/org/deepin/dde/Network1"; static QString localeName; @@ -42,7 +40,6 @@ NetworkController::NetworkController() , m_hotspotController(Q_NULLPTR) , m_connectivityHandler(new ConnectivityHandler(this)) { - Dtk::Core::loggerInstance()->setDefaultCategory(DNC().categoryName()); retranslate(QLocale().name()); if (ConfigSetting::instance()->serviceFromNetworkManager()) { @@ -152,9 +149,9 @@ void NetworkController::installTranslator(const QString &locale) } if (m_translator->load(QLocale(localeName), "dde-network-core", "_", "/usr/share/dde-network-core/translations")) { QCoreApplication::installTranslator(m_translator); - qInfo() << "Loaded translation file for dde-network-core:" << m_translator->filePath(); + qCInfo(DNC()) << "Loaded translation file for dde-network-core:" << m_translator->filePath(); } else { - qWarning() << "Failed to load translation file for dde-network-core"; + qCWarning(DNC()) << "Failed to load translation file for dde-network-core"; m_translator->deleteLater(); m_translator = nullptr; }