Loading...
Loading...
Compare original and translation side by side
| Log Level | Behavior | Use Case |
|---|---|---|
| LOGE | Always prints, never lost | Critical - Must exist on all error return paths |
| LOGI | Always prints, may be lost if high-frequency triggered at same location | Important - Success paths, key operations |
| LOGD | Only prints when debug switch enabled | Optional - Debug information only |
| LOGW | Only prints when debug switch enabled | Optional - Warning information only |
| 日志级别 | 行为 | 使用场景 |
|---|---|---|
| LOGE | 始终打印,不会丢失 | 关键场景 - 所有错误返回路径必须包含 |
| LOGI | 始终打印,若同一位置高频触发可能丢失 | 重要场景 - 成功路径、关键操作 |
| LOGD | 仅在调试开关开启时打印 | 可选场景 - 仅用于调试信息 |
| LOGW | 仅在调试开关开启时打印 | 可选场景 - 仅用于警告信息 |
TodoWriteTodoWriteTodoWriteTodoWriteGlob**/*.cpp**/*.cc**/*.cxx**/*.h**/*.hpp**/*.java**/*.py**/*.js**/*.ts**/*.go**/*.rs**/test/****/tests/****/*_test.***/build/****/out/****/target/**Glob**/*.cpp**/*.cc**/*.cxx**/*.h**/*.hpp**/*.java**/*.py**/*.js**/*.ts**/*.go**/*.rs**/test/****/tests/****/*_test.***/build/****/out/****/target/**GrepLOG[DEIW]HILOG[DEIW]ALOG[DEIW]\.log[deiw]\(Log\.[deiw]LOG\.GrepLOG[DEIW]HILOG[DEIW]ALOG[DEIW]\\.log[deiw]\\(Log\\.[deiw]LOG\\.OnDataReceivedOnPacketReceivedOnMessageOnTimerTickUpdateHandleEventProcessEventOnEventProcessItemHandlePacketSendDataProcessStreamHandleFrameEncodeFrameOnMessageDispatchOnDataReceivedOnPacketReceivedOnMessageOnTimerTickUpdateHandleEventProcessEventOnEventProcessItemHandlePacketSendDataProcessStreamHandleFrameEncodeFrameOnMessageDispatchWritelog-coverage-report-YYYYMMDD-HHmmss.mdWritelog-coverage-report-YYYYMMDD-HHmmss.md[return_type] [class::]function_name([parameters]) {
[\w\s:*,]*\{LOG[DEIW]\(HILOG[DEIW]\(ALOG[DEIW]\(__android_log_printOHOS::HiviewDFX::HiLog::[Error|Warn|Info|Debug][return_type] [class::]function_name([parameters]) {
[\\w\\s:*,]*\\{LOG[DEIW]\\(HILOG[DEIW]\\(ALOG[DEIW]\\(__android_log_printOHOS::HiviewDFX::HiLog::[Error|Warn|Info|Debug](public|private|protected)?(\s+static)?\s+\w+\s+\w+\s*\(.*\)\s*(throws\s+[\w\s,]+)?\s*\{Log\.[deiw]\(Logger\.(error|warn|info|debug)\(Timber\.[deiw]\((public|private|protected)?(\\s+static)?\\s+\\w+\\s+\\w+\\s*\\(.*\\)\\s*(throws\\s+[\\w\\s,]+)?\\s*\\{Log\\.[deiw]\\(Logger\\.(error|warn|info|debug)\\(Timber\\.[deiw]\\(def\s+\w+\s*\(.*\)\s*->?\s*.*:logger\.(error|warning|info|debug)\(logging\.(error|warning|info|debug)\(print\(def\\s+\\w+\\s*\\(.*\\)\\s*->?\\s*.*:logger\\.(error|warning|info|debug)\\(logging\\.(error|warning|info|debug)\\(print\\(function\s+\w+\s*\(.*\)\s*\{
|\w+\s*\([^)]*\)\s*(=>|\{)console\.(error|warn|info|log)\(logger\.(error|warn|info|debug)\(function\\s+\\w+\\s*\\(.*\\)\\s*\\{
|\\w+\\s*\\([^)]*\\)\\s*(=>|\\{)console\\.(error|warn|info|log)\\(logger\\.(error|warn|info|debug)\\(// BEFORE:
if (remote == nullptr) {
return ERR_NULL_OBJECT; // ❌ No LOGE
}
// AFTER:
if (remote == nullptr) {
HILOGE("FunctionName: remote is null, context=%{public}d", context);
return ERR_NULL_OBJECT;
}// BEFORE:
int32_t CreateSession(...) {
// ... initialization code
return ERR_OK; // ❌ No LOGI on success
}
// AFTER:
int32_t CreateSession(...) {
// ... initialization code
HILOGI("CreateSession: success, sessionId=%{public}d, name=%{public}s", id, name);
return ERR_OK;
}// 修复前:
if (remote == nullptr) {
return ERR_NULL_OBJECT; // ❌ 无LOGE
}
// 修复后:
if (remote == nullptr) {
HILOGE("FunctionName: remote is null, context=%{public}d", context);
return ERR_NULL_OBJECT;
}// 修复前:
int32_t CreateSession(...) {
// ... 初始化代码
return ERR_OK; // ❌ 成功路径无LOGI
}
// 修复后:
int32_t CreateSession(...) {
// ... 初始化代码
HILOGI("CreateSession: success, sessionId=%{public}d, name=%{public}s", id, name);
return ERR_OK;
}// BEFORE:
void OnPacketReceived(int socketId, const void* data, uint32_t len) {
HILOGI("packet received: socket=%{public}d, len=%{public}u", socketId, len); // ⚠️ Per-packet
// ... process packet
}
// AFTER:
void OnPacketReceived(int socketId, const void* data, uint32_t len) {
// Removed per-packet LOGI
static std::atomic<uint64_t> packetCount{0};
if (++packetCount % 1000 == 1) {
HILOGI("Packet stats: count=%{public}llu, socket=%{public}d",
packetCount.load(), socketId);
}
// ... process packet
}// BEFORE:
void ProcessPacket(const Packet* pkt) {
if (pkt == nullptr) {
HILOGE("packet is null"); // ⚠️ Per-packet error
return;
}
}
// AFTER:
void ProcessPacket(const Packet* pkt) {
if (pkt == nullptr) {
static std::atomic<uint32_t> errorCount{0};
if (++errorCount % 100 == 1) {
HILOGE("ProcessPacket: null packet, count=%{public}u", errorCount.load());
}
return;
}
}// 修复前:
void OnPacketReceived(int socketId, const void* data, uint32_t len) {
HILOGI("packet received: socket=%{public}d, len=%{public}u", socketId, len); // ⚠️ 每个数据包都打印
// ... 处理数据包
}
// 修复后:
void OnPacketReceived(int socketId, const void* data, uint32_t len) {
// 移除每个数据包的LOGI
static std::atomic<uint64_t> packetCount{0};
if (++packetCount % 1000 == 1) {
HILOGI("Packet stats: count=%{public}llu, socket=%{public}d",
packetCount.load(), socketId);
}
// ... 处理数据包
}// 修复前:
void ProcessPacket(const Packet* pkt) {
if (pkt == nullptr) {
HILOGE("packet is null"); // ⚠️ 每个错误数据包都打印
return;
}
}
// 修复后:
void ProcessPacket(const Packet* pkt) {
if (pkt == nullptr) {
static std::atomic<uint32_t> errorCount{0};
if (++errorCount % 100 == 1) {
HILOGE("ProcessPacket: null packet, count=%{public}u", errorCount.load());
}
return;
}
}================================================================================
Log Coverage Analysis Report
================================================================================
Repository: <repository_path>
Analysis Date: <timestamp>
Files Analyzed: <count>================================================================================
日志覆盖率分析报告
================================================================================
仓库路径: <repository_path>
分析日期: <timestamp>
分析文件数: <count>| Metric | Count |
|---|---|
| Total Source Files | <number> |
| Total Functions | <number> |
| Functions Analyzed | <number> |
| Log Deficiencies | <number> |
| High-Frequency Risks | <number> |
| 指标 | 数量 |
|---|---|
| 总源文件数 | <number> |
| 总函数数 | <number> |
| 已分析函数数 | <number> |
| 日志缺失数 | <number> |
| 高频风险数 | <number> |
<file_path><function_name><line_range><description><code snippet><fixed code><file_path><function_name><line_range><description><code snippet><修复后的代码><file_path><function_name><line_range><code snippet><fixed code with throttling/statistics><file_path><function_name><line_range><code snippet><带限流/统计的修复代码><function_1>()
↓ [✓/✗/⚠️] <log_status>
<function_2>()
↓ [✓/✗/⚠️] <log_status>
<function_3>()
├─ [✓/✗/⚠️] branch_1
├─ [✓/✗/⚠️] branch_2
└─ [✓/✗/⚠️] branch_3<function_1>()
↓ [✓/✗/⚠️] <日志状态>
<function_2>()
↓ [✓/✗/⚠️] <日志状态>
<function_3>()
├─ [✓/✗/⚠️] branch_1
├─ [✓/✗/⚠️] branch_2
└─ [✓/✗/⚠️] branch_3undefinedundefined| Parameter | Required | Description |
|---|---|---|
| No | Repository path (default: current directory) |
| No | Exclude test files (default: true) |
| No | Language filter (cpp, java, python, js, all) |
| No | Output report path |
| 参数 | 是否必填 | 描述 |
|---|---|---|
| 否 | 仓库路径(默认:当前目录) |
| 否 | 排除测试文件(默认:true) |
| 否 | 语言过滤(cpp, java, python, js, all) |
| 否 | 报告输出路径 |
undefinedundefinedundefinedundefinedGrepoutput_mode: content-B/-CReadoffsetlimitGrepoutput_mode: content-B/-CReadoffsetlimit