Skip to content

Conversation

@caixr23
Copy link
Contributor

@caixr23 caixr23 commented Jan 14, 2026

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. 使用不同日志级别验证日志过滤功能

Summary by Sourcery

Adopt categorized logging and minor QML utility adjustments across network components.

Enhancements:

  • Replace direct qWarning/qInfo usages with categorized logging macros (qCWarning/qCInfo) using existing DNC and DSM categories in network-related modules.
  • Include the NetworkConst header where needed for categorized logging usage and remove redundant default logger category configuration in NetworkController.
  • Remove redundant debug logging in BubbleManager notification closing logic to reduce log noise.
  • Add a .pragma library directive to NetUtils.js so its utilities are treated as a shared QML library script.

@caixr23 caixr23 requested a review from robertkill January 14, 2026 08:36
@sourcery-ai
Copy link

sourcery-ai bot commented Jan 14, 2026

Reviewer's Guide

Replaces direct qWarning/qInfo calls with categorized logging macros (qCWarning/qCInfo) using the DNC and DSM logging categories, adds required network logging/header dependencies, removes an obsolete default logger category configuration, and marks NetUtils.js as a QML library script for better reuse.

Flow diagram for QML NetUtils.js as a shared library script

graph TD
    NetUtils[NetUtils.js with .pragma library]
    QMLCompA[QML component A]
    QMLCompB[QML component B]
    QMLCompC[QML component C]

    QMLCompA -->|import and call functions| NetUtils
    QMLCompB -->|import and call functions| NetUtils
    QMLCompC -->|import and call functions| NetUtils

    NetUtils -->|shared script state and functions| NetUtils
Loading

File-Level Changes

Change Details Files
Switch network-related warning/info logging to categorized logging macros using DNC and DSM categories.
  • Replace qWarning and qInfo usages with qCWarning(DNC()) or qCInfo(DNC()) in controller and plugin code paths
  • Use qCWarning(DSM) in service-layer utilities and system initialization code when reporting DBus and file I/O errors
  • Add missing networkconst.h includes where DNC logging category is now required
dcc-network/operation/dccnetwork.cpp
network-service-plugin/src/utils/constants.cpp
src/networkcontroller.cpp
dss-network-plugin/networkmodule.cpp
src/dbus/proxychains.cpp
network-service-plugin/src/system/networkinitialization.cpp
Adjust logging configuration and clean up noisy debug output in notification handling.
  • Remove global default logging category setup from the NetworkController constructor since categorized logging macros now specify categories explicitly
  • Drop redundant qDebug output when closing notifications to reduce log noise
src/networkcontroller.cpp
dss-network-plugin/notification/bubblemanager.cpp
Improve QML module handling for shared network utilities script.
  • Add .pragma library directive to NetUtils.js to ensure its functions are shared as a library script across QML components
dcc-network/qml/NetUtils.js

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 2 issues, and left some high level feedback:

  • In NetworkController, removing Dtk::Core::loggerInstance()->setDefaultCategory(DNC().categoryName()); changes the global default logging category; if other components rely on that default, consider either keeping it or explicitly setting categories at those call sites to avoid unexpected logging behavior.
  • In BubbleManager::CloseNotification the qDebug calls were removed rather than replaced with categorized logging; if these messages are still useful for diagnosing notification issues, consider reintroducing them as qCDebug(DNC()) so they can be filtered via the category.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In NetworkController, removing `Dtk::Core::loggerInstance()->setDefaultCategory(DNC().categoryName());` changes the global default logging category; if other components rely on that default, consider either keeping it or explicitly setting categories at those call sites to avoid unexpected logging behavior.
- In BubbleManager::CloseNotification the `qDebug` calls were removed rather than replaced with categorized logging; if these messages are still useful for diagnosing notification issues, consider reintroducing them as `qCDebug(DNC())` so they can be filtered via the category.

## Individual Comments

### Comment 1
<location> `dss-network-plugin/networkmodule.cpp:292-296` </location>
<code_context>
     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;
</code_context>

<issue_to_address>
**nitpick (typo):** Fix typos and wording in user-visible log / response strings.

These user-facing strings have small English errors: `"containt"``"contain"`, and `"msgData don't containt data"` could be rephrased for clarity (e.g. `"msgData does not contain data"`). Since they appear in logs/JSON responses, please correct the wording.

```suggestion
    if (!jsonObject.contains("data")) {
        qCWarning(DNC()) << "msgData does not contain 'data' field" << msgData;
        QJsonDocument jsonResult;
        QJsonObject resultObject;
        resultObject.insert("data", QString("msgData does not contain 'data' field: %1").arg(msgData));
        QDBusPendingCall reply = dbusInter.asyncCall("UpdateLanguage", locale);
        reply.waitForFinished();
    } else {
        qCWarning(DNC()) << networkService << "has not started yet; waiting for it to start";
```
</issue_to_address>

### Comment 2
<location> `src/dbus/proxychains.cpp:116` </location>
<code_context>
     }

-    qWarning() << "On property changed,property not handle: " << propName;
+    qCWarning(DNC()) << "On property changed,property not handle: " << propName;
     return;
 }
</code_context>

<issue_to_address>
**suggestion (typo):** Improve log message wording and punctuation.

This log string is a bit unclear. Consider wording like `"Property change not handled:"` or `"Unhandled property change:"`. Also, the comma is a full-width Chinese ``; unless that’s intentional, use a standard ASCII comma for consistency with other logs.

```suggestion
    qCWarning(DNC()) << "Unhandled property change:" << propName;
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

}

qWarning() << "On property changed,property not handle: " << propName;
qCWarning(DNC()) << "On property changed,property not handle: " << propName;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (typo): Improve log message wording and punctuation.

This log string is a bit unclear. Consider wording like "Property change not handled:" or "Unhandled property change:". Also, the comma is a full-width Chinese ; unless that’s intentional, use a standard ASCII comma for consistency with other logs.

Suggested change
qCWarning(DNC()) << "On property changed,property not handle: " << propName;
qCWarning(DNC()) << "Unhandled property change:" << propName;

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request replaces direct qWarning() and qInfo() calls with categorized logging macros (qCWarning(), qCInfo()) to improve logging consistency and enable better log filtering. The PR also removes obsolete logging configuration, cleans up redundant debug statements, and adds a .pragma library directive to a QML utility script.

Changes:

  • Replaced all qWarning() and qInfo() calls with categorized equivalents using DNC() or DSM logging categories
  • Removed obsolete DLog include and setDefaultCategory() call from NetworkController
  • Removed redundant qDebug() statements from BubbleManager
  • Added .pragma library directive to NetUtils.js for proper QML module handling

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/networkcontroller.cpp Removed DLog dependency and setDefaultCategory call; converted qInfo/qWarning to qCInfo/qCWarning with DNC category
src/dbus/proxychains.cpp Added networkconst.h include; converted qWarning to qCWarning with DNC category
network-service-plugin/src/utils/constants.cpp Converted qWarning calls to qCWarning with DSM category in dbusDebug function
network-service-plugin/src/system/networkinitialization.cpp Converted qWarning to qCWarning with DSM category
dss-network-plugin/notification/bubblemanager.cpp Removed redundant qDebug logging statements
dss-network-plugin/networkmodule.cpp Converted qWarning to qCWarning with DNC category
dcc-network/qml/NetUtils.js Added .pragma library directive for proper QML module handling
dcc-network/operation/dccnetwork.cpp Added networkconst.h include; converted qWarning to qCWarning with DNC category; cleaned up trailing whitespace

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

mhduiy
mhduiy previously approved these changes Jan 15, 2026
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. 使用不同日志级别验证日志过滤功能
@deepin-ci-robot
Copy link

deepin pr auto review

这段代码主要涉及网络模块的日志系统改造和一些代码格式调整。我将从语法逻辑、代码质量、性能和安全四个方面进行审查:

1. 语法逻辑

优点:

  • 日志系统从 qWarning()/qInfo() 统一迁移到 qCWarning(DNC())/qCInfo(DNC()),使用了分类日志,符合 Qt 的最佳实践
  • NetUtils.js 中添加了 .pragma library 声明,这是正确的做法,表明这是一个纯函数库

改进建议:

  • dccnetwork.cpp 中,IPv6 DNS 的处理逻辑仍然不完整:

    // 第82行
    qCWarning(DNC()) << "IPv6 DNS not fully implemented in backend, DNS:" << dnsStr;
    // 这里需要实现IPv6 DNS的完整支持

    建议补充实现 IPv6 DNS 的支持,或者至少添加 TODO 标记和功能追踪编号。

  • networkmodule.cpp 中,错误消息的英文表达不够准确:

    // 第293行
    qCWarning(DNC()) << "msgData don't containt data" << msgData;

    "containt" 应该是 "contain",且 "don't" 在正式日志中应改为 "does not" 或 "doesn't"

2. 代码质量

优点:

  • 移除了冗余的调试日志输出(如 bubblemanager.cpp 中的 qDebug()
  • 日志信息更加结构化,便于后续日志分析和调试
  • 代码格式统一,移除了多余的空行

改进建议:

  • networkcontroller.cpp 中,移除了 Dtk::Core::loggerInstance()->setDefaultCategory() 的调用,但需要确认:

    1. networkconst.h 中是否正确定义了 DNC()
    2. 日志系统初始化是否在其他地方完成
    3. 是否需要添加日志配置初始化的文档说明
  • 建议在 networkconst.h 中添加日志分类的详细注释,说明 DNC()DSM() 的用途

3. 代码性能

优点:

  • 使用分类日志系统可以在运行时控制日志输出级别,有助于生产环境性能优化

改进建议:

  • dccnetwork.cpp 的 IPv6 DNS 处理部分:

    for (const QHostAddress &addr : ipv6DnsAddresses) {
        ipv6DnsStrings.append(addr.toString());
    }

    可以使用 QStringListreserve() 预分配空间:

    ipv6DnsStrings.reserve(ipv6DnsAddresses.size());
    for (const QHostAddress &addr : ipv6DnsAddresses) {
        ipv6DnsStrings.append(addr.toString());
    }
  • constants.cppdbusDebug 函数中:

    QByteArray cmd = file.readAll();
    qCWarning(DSM) << "API" << funName << "is called by" << service << "(" << cmd.split('\0').join(" ") << ")";

    建议限制读取的命令行长度,避免读取过长的命令行字符串影响性能:

    QByteArray cmd = file.readAll().left(1024); // 限制最大长度

4. 代码安全

优点:

  • 使用分类日志系统可以更好地控制敏感信息的输出

改进建议:

  • constants.cpp 中,直接读取 /proc/[pid]/cmdline 可能存在安全隐患:

    QFile file(QString("/proc/%1/cmdline").arg(pid));

    建议:

    1. 添加对 pid 的有效性检查
    2. 使用 QFile::exists() 检查文件是否存在
    3. 添加权限检查
    4. 考虑对读取的命令行进行脱敏处理,避免泄露敏感信息

    改进示例:

    if (pid <= 0) {
        qCWarning(DSM) << "Invalid PID:" << pid;
        return;
    }
    
    QString filePath = QString("/proc/%1/cmdline").arg(pid);
    QFile file(filePath);
    if (!file.exists() || !file.open(QFile::ReadOnly)) {
        qCWarning(DSM) << "Failed to open cmdline file:" << filePath;
        return;
    }
    
    QByteArray cmd = file.readAll();
    // 可选:对敏感信息进行脱敏
    qCWarning(DSM) << "API" << funName << "is called by" << service << "(" << sanitizeCmdline(cmd) << ")";
  • networkmodule.cpp 中处理 JSON 数据时:

    QJsonDocument json = QJsonDocument::fromJson(msgData.toLatin1());

    建议添加 JSON 解析错误处理:

    QJsonParseError parseError;
    QJsonDocument json = QJsonDocument::fromJson(msgData.toLatin1(), &parseError);
    if (parseError.error != QJsonParseError::NoError) {
        qCWarning(DNC()) << "Failed to parse JSON:" << parseError.errorString();
        return QString();
    }

总结

这次代码修改主要集中在对日志系统的规范化改造,整体方向正确。建议重点关注:

  1. 完善 IPv6 DNS 的实现
  2. 加强错误处理和输入验证
  3. 优化性能关键路径
  4. 完善文档和注释

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: 18202781743, caixr23

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@caixr23 caixr23 merged commit e730761 into linuxdeepin:master Jan 15, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants