skills/log-coverage-analyzer/SKILL.md
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 skillsauth add openharmonyinsight/openharmony-skills log-coverage-analyzerInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill performs comprehensive log coverage analysis for code repositories. It identifies logging deficiencies in call chains and detects high-frequency log risks that may impact performance.
| 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 |
Description: Create detailed analysis plan before starting
Actions:
TodoWrite tool to create task listOutput: Analysis plan created via TodoWrite tool
Description: Find all relevant source files in the repository
Actions:
Glob tool to find source files based on language patterns:
**/*.cpp, **/*.cc, **/*.cxx, **/*.h, **/*.hpp**/*.java**/*.py**/*.js, **/*.ts**/*.go**/*.rs**/test/**, **/tests/**, **/*_test.*)**/build/**, **/out/**, **/target/**)Output: List of source files to analyze
Description: Scan all source files for logging macros/functions
Actions:
Grep tool to find log statements with pattern:
LOG[DEIW], HILOG[DEIW], ALOG[DEIW]\.log[deiw]\(, Log\.[deiw], LOG\.Output: Log statistics per file
Description: Parse source files to extract function definitions and call relationships
Actions:
Output: Function list with call relationships
Description: Check each branch in call chains for required logging
Actions:
Deficiency Classification:
Output: List of log deficiencies with locations
Description: Identify functions with LOGE/LOGI that may be called frequently
Actions:
OnDataReceived, OnPacketReceived, OnMessage)OnTimer, Tick, Update)HandleEvent, ProcessEvent, OnEvent)ProcessItem, HandlePacket, SendData)ProcessStream, HandleFrame, EncodeFrame)OnMessage, Dispatch)Risk Classification:
Output: List of high-frequency risks with locations
Description: Create comprehensive analysis report with all findings
Actions:
Write tool to save report to log-coverage-report-YYYYMMDD-HHmmss.mdOutput: Complete analysis report
Function Definition Patterns:
[return_type] [class::]function_name([parameters]) {
[\w\s:*,]*\{
Log Patterns:
LOG[DEIW]\(, HILOG[DEIW]\(, ALOG[DEIW]\(__android_log_printOHOS::HiviewDFX::HiLog::[Error|Warn|Info|Debug]Function Definition Patterns:
(public|private|protected)?(\s+static)?\s+\w+\s+\w+\s*\(.*\)\s*(throws\s+[\w\s,]+)?\s*\{
Log Patterns:
Log\.[deiw]\(Logger\.(error|warn|info|debug)\(Timber\.[deiw]\(Function Definition Patterns:
def\s+\w+\s*\(.*\)\s*->?\s*.*:
Log Patterns:
logger\.(error|warning|info|debug)\(logging\.(error|warning|info|debug)\(print\(Function Definition Patterns:
function\s+\w+\s*\(.*\)\s*\{
|\w+\s*\([^)]*\)\s*(=>|\{)
Log Patterns:
console\.(error|warn|info|log)\(logger\.(error|warn|info|debug)\(Error Return Path (Must Fix):
// 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;
}
Success Path (Should Fix):
// 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;
}
Remove High-Frequency LOGI:
// 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
}
Use Throttled LOGE for Errors:
// 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>
Impact: <explain impact on debugging/troubleshooting>
Fix:
<fixed code>
File: <file_path>
Function: <function_name>
Lines: <line_range>
Risk: <description>
Evidence:
<code snippet>
Analysis: <explain why this is high-frequency>
Fix:
<fixed code with throttling/statistics>
<function_1>()
↓ [✓/✗/⚠️] <log_status>
<function_2>()
↓ [✓/✗/⚠️] <log_status>
<function_3>()
├─ [✓/✗/⚠️] branch_1
├─ [✓/✗/⚠️] branch_2
└─ [✓/✗/⚠️] branch_3
Legend:
================================================================================
## 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
/log-coverage-analyzer
/log-coverage-analyzer --path /path/to/repo
/log-coverage-analyzer --lang cpp --path /path/to/repo
/log-coverage-analyzer --exclude-tests false
/log-coverage-analyzer --output /path/to/report.md
## 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
development
Run local code quality checks covering a subset of OpenHarmony gate CI (copyright, CodeArts C/C++) plus additional local checks (pylint/flake8, shellcheck/bashate, gn format). Use before committing to reduce gate failures. Triggers on: /oh-precommit-codecheck, "门禁检查", "门禁预检", "检查代码", "run codecheck", "check code quality", "lint my code", "代码检查", or after completing code implementation. WHEN to use: before git commit, before creating PR, after modifying C/C++/Python/Shell/GN files, when gate CI fails with codecheck defects, or when you want to preview what gate will flag.
development
OpenHarmony PR full lifecycle workflow. Five modes: - Commit: standardized commit with DCO sign-off and Issue linking - Create PR: commit + push to fork + create Issue + create PR on upstream - Fix Codecheck: fetch gate CI codecheck defects from a PR and auto-fix them - Review PR: fetch a PR's changes to local for code review - Fix Review: fetch unresolved review comments from a PR and auto-fix them Triggers on: /oh-pr-workflow, "提交代码", "创建PR", "提个PR", "commit", "修复告警", "修复门禁", "修复codecheck", "fix codecheck", "review pr", "review这个pr", "看下这个pr", "检视pr", "修复review", "修复检视意见", "fix review", or a GitCode PR URL with fix/review intent.
testing
分析 HM Desktop PRD 文档,提取需求信息、验证完整性、检查章节顺序(需求来源→需求背景→需求价值分析→竞品分析→需求描述)、检查 KEP 定义、检测需求冲突并生成结构化分析报告。适用于用户请求:(1) 分析或审查 PRD 文档, (2) 从需求中提取 KEP 列表, (3) 检查 PRD 完整性或一致性, (4) 将需求映射到模块架构, (5) 验证 PRD 格式合规性, (6) 验证竞品分析章节完整性。关键词:PRD分析, requirement extraction, KEP验证, completeness check, chapter order validation, 竞品分析检查, analyze PRD, 需求提取, 完整性检查, 章节顺序验证
development
基于 PRD 文档自动生成鸿蒙系统设计文档,包括架构设计文档和功能设计文档。生成前会分析 OpenHarmony 存量代码结构,确保与现有架构兼容。架构设计文档第2章必须为竞品方案分析,位于需求背景之后。适用于用户请求:(1) 生成架构设计文档, (2) 生成功能设计文档, (3) 从 PRD 生成设计文档, (4) 创建系统架构设计, (5) 编写功能规格说明, (6) 分析 OH 代码结构。关键词:architecture design, functional design, design doc, 竞品方案分析, OpenHarmony code analysis, 架构设计, 功能设计, 设计文档生成, OH代码分析, analyze codebase, competitor analysis