fix: use QJsonObject for event logger messages#187
fix: use QJsonObject for event logger messages#187Ivy233 wants to merge 1 commit intolinuxdeepin:masterfrom
Conversation
Use QJsonObject directly for EventLoggerData messages so JSON payloads are preserved when writing event logs. Remove the string key/value helper that no longer matches the object-based message payload. 使用 QJsonObject 直接承载 EventLoggerData 的 message 字段,确保写入事件日志时保留 JSON 载荷内容。移除不再匹配对象化 message 载荷的字符串键值辅助接口。
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Ivy233 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors EventLoggerData to store event messages as a QJsonObject instead of a string map so structured JSON payloads are preserved, and simplifies EventLogger by removing the now-mismatched string key/value helper and serializing the stored QJsonObject directly. Class diagram for updated EventLoggerData and EventLoggerclassDiagram
class EventLoggerData {
qint64 tid
QString target
QJsonObject message
EventLoggerData()
EventLoggerData(qint64 tid, const QString &target, const QJsonObject &message)
}
class EventLogger {
void writeEventLog(const EventLoggerData &data)
bool init(QString package_id, bool enable_sig)
QJsonDocument toJson(EventLoggerData data)
}
EventLogger --> EventLoggerData : uses
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- If simple key/value logging is still a common case, consider keeping a convenience
writeEventLog(tid, target, key, value)that internally constructs aQJsonObjectso existing call sites don’t all have to manually build JSON objects. - Since
EventLoggerData::messagechanged type, double-check any implicit uses (e.g., brace-initialization with{ {"key", "value"} }) still behave as intended withQJsonObject, or consider adding explicit factory/helpers to make the new usage pattern clearer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- If simple key/value logging is still a common case, consider keeping a convenience `writeEventLog(tid, target, key, value)` that internally constructs a `QJsonObject` so existing call sites don’t all have to manually build JSON objects.
- Since `EventLoggerData::message` changed type, double-check any implicit uses (e.g., brace-initialization with `{ {"key", "value"} }`) still behave as intended with `QJsonObject`, or consider adding explicit factory/helpers to make the new usage pattern clearer.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
deepin pr auto review这段代码的修改主要是将 1. 语法与逻辑审查
2. 代码质量改进意见
3. 代码性能改进意见
4. 代码安全改进意见
总结这个 diff 是一个积极的改动,它简化了数据转换逻辑,利用了 JSON 原生对象减少了中间转换。 推荐修改后的代码片段示例(结合了上述建议): #include <QJsonObject>
#include <QJsonDocument>
#include <QString>
// 使用 using 替代 typedef
using EventLoggerData = struct _EventLoggerData
{
qint64 tid = 0; // 类内初始化,简化构造函数
QString target;
QJsonObject message;
// 默认构造函数使用 = default
_EventLoggerData() = default;
// 参数按值传递,利用移动语义优化性能
_EventLoggerData(qint64 tid, QString target, QJsonObject message)
: tid(tid)
, target(std::move(target))
, message(std::move(message))
{
}
};在 // ... 其他代码 ...
QJsonDocument formatEventLog(const EventLoggerData &data) const // 建议加上 const
{
QJsonObject jsonObject;
jsonObject["tid"] = data.tid;
jsonObject["target"] = data.target;
// 直接赋值,利用隐式共享,非常高效
jsonObject["message"] = data.message;
return QJsonDocument(jsonObject);
} |
Use QJsonObject directly for EventLoggerData messages so JSON payloads are preserved when writing event logs. Remove the string key/value helper that no longer matches the object-based message payload.
使用 QJsonObject 直接承载 EventLoggerData 的 message 字段,确保写入事件日志时保留 JSON 载荷内容。移除不再匹配对象化 message 载荷的字符串键值辅助接口。
Summary by Sourcery
Switch event logger message payloads to use QJsonObject instead of string maps to preserve structured JSON data.
Bug Fixes:
Enhancements: