Loading...
Loading...
Analyze code repository logging coverage to ensure all function branches have LOGE/LOGI logs and identify high-frequency log risks. Supports multiple programming languages (C++, Java, Python, JavaScript, etc.)
npx skill4agent add openharmonyinsight/openharmony-skills log-coverage-analyzer| 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 |
TodoWriteTodoWriteGlob**/*.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\.OnDataReceivedOnPacketReceivedOnMessageOnTimerTickUpdateHandleEventProcessEventOnEventProcessItemHandlePacketSendDataProcessStreamHandleFrameEncodeFrameOnMessageDispatchWritelog-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](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\(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;
}// 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;
}
}================================================================================
Log Coverage Analysis Report
================================================================================
Repository: <repository_path>
Analysis Date: <timestamp>
Files Analyzed: <count>
## Summary Statistics
| Metric | Count |
|--------|-------|
| Total Source Files | <number> |
| Total Functions | <number> |
| Functions Analyzed | <number> |
| Log Deficiencies | <number> |
| High-Frequency Risks | <number> |
## Log Deficiencies
### [High/Medium/Low] Priority
**File**: `<file_path>`
**Function**: `<function_name>`
**Lines**: `<line_range>`
**Issue**: `<description>`
**Evidence**:
```cpp
<code snippet><fixed code><file_path><function_name><line_range><code snippet><fixed code with throttling/statistics><function_1>()
↓ [✓/✗/⚠️] <log_status>
<function_2>()
↓ [✓/✗/⚠️] <log_status>
<function_3>()
├─ [✓/✗/⚠️] branch_1
├─ [✓/✗/⚠️] branch_2
└─ [✓/✗/⚠️] branch_3
## Parameters
| Parameter | Required | Description |
|-----------|----------|-------------|
| `--path` | No | Repository path (default: current directory) |
| `--exclude-tests` | No | Exclude test files (default: true) |
| `--lang` | No | Language filter (cpp, java, python, js, all) |
| `--output` | No | Output report path |
## Usage Examples
## Tips
- Use `Grep` with `output_mode: content` and `-B/-C` flags for context
- Use `Read` tool with `offset` and `limit` for large files
- For large repositories, focus on critical directories first
- High-frequency risks should be prioritized over minor log deficiencies
- Always include context (IDs, states, parameters) in LOGE messages