Logo Log Coverage Analyzer

Log Coverage Analyzer

Tổ chức
openharmonyinsight
log-coverage-analyzer

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.)

Tổng quan

Nhà phát hànhopenharmonyinsight
Kho mãopenharmony-skills
Tên kỹ nănglog-coverage-analyzer
Sao
36
Bản fork
7
Tệp đi kèm
Chỉ có hướng dẫn
Giấy phépMIT
Liên kết
  • Hướng dẫn bằng Markdown

    Tệp SKILL.md được mô hình tải khi cần, nên chỉ tốn token khi có yêu cầu thực sự phù hợp.

  • Dùng được với mọi LLM

    Kỹ năng AI là Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên dùng được với GPT, Claude, Gemini, Grok hoặc mô hình cục bộ.

  • Đầy đủ trong hướng dẫn

    Mọi thứ mô hình cần đều nằm trong hướng dẫn — không có tệp bổ sung cần đồng bộ.

  • Mã nguồn mở

    Được openharmonyinsight công bố trên GitHub. Hãy đọc nội dung nguồn trước khi cài đặt.

Cài đặt

Cài đặt kỹ năng AI Log Coverage Analyzer trong TypingMind để dùng với bất kỳ LLM nào, hoặc thêm vào một tác nhân AI khác có thể đọc SKILL.md.

1

Cài đặt trong TypingMind

TypingMind cài đặt kỹ năng trực tiếp từ thư mục GitHub — đọc SKILL.md, đóng gói các tệp tài nguyên và lưu kết quả trên máy.

  1. Mở ứng dụng và vào Plugin → Kỹ năng.
  2. Chọn "Cài đặt từ GitHub".
  3. Dán URL thư mục kỹ năng bên dưới và xác nhận.
    https://github.com/openharmonyinsight/openharmony-skills/tree/main/skills/log-coverage-analyzer
  4. Bật kỹ năng trong từng cuộc trò chuyện mà bạn muốn sử dụng kỹ năng đó.
Plugin → Kỹ năng → Thêm kỹ năng → Từ URL GitHub, sau đó dán URL thư mục và nhấn Tiếp tục.
2

Cài đặt trong tác nhân AI khác

Bất kỳ tác nhân AI nào đọc được định dạng Agent Skills đều có thể dùng kỹ năng này — hãy sao chép thư mục vào thư mục kỹ năng của tác nhân AI đó.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/openharmonyinsight/openharmony-skills.git /tmp/openharmony-skills
mkdir -p .claude/skills
cp -r /tmp/openharmony-skills/skills/log-coverage-analyzer .claude/skills/log-coverage-analyzer
Khởi động lại Claude Code sau khi sao chép để ứng dụng nhận kỹ năng mới.

Sử dụng trong TypingMind

Bật Log Coverage Analyzer trong bất kỳ cuộc trò chuyện nào trên TypingMind, mô hình sẽ tự xử lý phần còn lại. Tên và mô tả của kỹ năng nằm trong prompt hệ thống. Ngay khi có yêu cầu phù hợp, mô hình tự tải toàn bộ hướng dẫn — bạn không cần gọi thủ công và kỹ năng không tốn token cho đến khi thực sự được dùng.

Mô hình tự tải Log Coverage Analyzer ngay khi có yêu cầu phù hợp.

Dùng được với mọi mô hình AI

Kỹ năng AI là các hướng dẫn Markdown thuần túy, không phải mã dành riêng cho một nhà cung cấp, nên Log Coverage Analyzer không bị giới hạn ở mô hình mà kỹ năng này được viết cho. Chỉ cần cài đặt một lần trong TypingMind rồi dùng với GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama hoặc mô hình cục bộ do bạn tự chạy — tất cả đều dùng khóa API của riêng bạn.

  • Chỉ tải khi cần

    Prompt hệ thống chỉ chứa tên và mô tả. Hướng dẫn được tải khi có yêu cầu phù hợp đầu tiên, nên kỹ năng chưa dùng không tốn chi phí.

  • Đổi mô hình ngay trong cuộc trò chuyện

    Vì kỹ năng là hướng dẫn chứ không phải mã, việc đổi mô hình không làm kỹ năng ngừng hoạt động — mô hình tiếp theo vẫn đọc cùng tệp SKILL.md.

Hướng dẫn của kỹ năng

Đây là nội dung SKILL.md mà mô hình tải. Hãy đọc trước khi cài đặt — kỹ năng là những hướng dẫn mà mô hình của bạn sẽ làm theo.

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.

Analysis Principles

Log Level Definitions

Log LevelBehaviorUse Case
LOGEAlways prints, never lostCritical - Must exist on all error return paths
LOGIAlways prints, may be lost if high-frequency triggered at same locationImportant - Success paths, key operations
LOGDOnly prints when debug switch enabledOptional - Debug information only
LOGWOnly prints when debug switch enabledOptional - Warning information only

Core Analysis Rules

  1. Log Coverage Rule: Each branch in a function call chain must have LOGE or LOGI level logging
  2. High-Frequency Risk Rule: Functions that may be called frequently (loops, timers, callbacks, event handlers) with LOGE/LOGI logs pose performance risks
  3. Error Path Rule: All error return paths MUST have LOGE logging
  4. Context Rule: All logs must include sufficient context information (IDs, states, parameters)

Execution Workflow

Step 00: Create Analysis Plan

Description: Create detailed analysis plan before starting

Actions:

  • Use TodoWrite tool to create task list
  • Plan analysis scope:
    • Source file discovery and filtering
    • Function call chain extraction
    • Log coverage analysis per branch
    • High-frequency risk detection
    • Report generation

Output: Analysis plan created via TodoWrite tool

Step 01: Discover Source Files

Description: Find all relevant source files in the repository

Actions:

  • Use Glob tool to find source files based on language patterns:
    • C/C++: **/*.cpp, **/*.cc, **/*.cxx, **/*.h, **/*.hpp
    • Java: **/*.java
    • Python: **/*.py
    • JavaScript/TypeScript: **/*.js, **/*.ts
    • Go: **/*.go
    • Rust: **/*.rs
  • Exclude test files if specified (patterns: **/test/**, **/tests/**, **/*_test.*)
  • Exclude build directories (patterns: **/build/**, **/out/**, **/target/**)

Output: List of source files to analyze

Step 02: Scan Logging Patterns

Description: Scan all source files for logging macros/functions

Actions:

  • Use Grep tool to find log statements with pattern:
    • Case-insensitive search for: LOG[DEIW], HILOG[DEIW], ALOG[DEIW]
    • Also search for: \.log[deiw]\(, Log\.[deiw], LOG\.
  • Count occurrences per file
  • Identify log level distribution

Output: Log statistics per file

Step 03: Extract Functions and Call Chains

Description: Parse source files to extract function definitions and call relationships

Actions:

  • For each source file:
    • Identify function definitions (various patterns per language)
    • Extract function bodies including all branches
    • Identify function calls within each function
    • Build call chain graph
  • Map branch conditions (if/else, switch/case, try/catch, early returns)

Output: Function list with call relationships

Step 04: Analyze Log Coverage per Branch

Description: Check each branch in call chains for required logging

Actions:

  • For each function in call chain:
    • Identify all branches:
      • Early returns
      • if/else branches
      • switch/case branches
      • try/catch blocks
      • loop exits with error conditions
    • Check each branch for LOGE or LOGI presence
    • Flag branches without required logging as Log Deficiency
    • Check error return paths specifically for LOGE

Deficiency Classification:

  • High Priority: Error return path without LOGE
  • Medium Priority: Success path without LOGI for multi-step operations
  • Low Priority: Branch without any logging (non-critical)

Output: List of log deficiencies with locations

Step 05: Detect High-Frequency Log Risks

Description: Identify functions with LOGE/LOGI that may be called frequently

Actions:

  • Identify high-frequency function patterns:
    • Network data callbacks (OnDataReceived, OnPacketReceived, OnMessage)
    • Timer callbacks (OnTimer, Tick, Update)
    • Event handlers (HandleEvent, ProcessEvent, OnEvent)
    • Loop operations (ProcessItem, HandlePacket, SendData)
    • Stream processing (ProcessStream, HandleFrame, EncodeFrame)
    • Message queue handlers (OnMessage, Dispatch)
  • For functions with LOGE/LOGI in these patterns:
    • Analyze call frequency potential
    • Classify risk level: High/Medium/Low
    • Flag as High-Frequency Risk

Risk Classification:

  • High Risk: Per-packet/per-frame LOGE/LOGI in data path
  • Medium Risk: Per-message LOGI in messaging path
  • Low Risk: Low-frequency callbacks with logs

Output: List of high-frequency risks with locations

Step 06: Generate Analysis Report

Description: Create comprehensive analysis report with all findings

Actions:

  • Generate Markdown report with:
    1. Summary statistics
    2. Log deficiencies with fix suggestions
    3. High-frequency risks with fix suggestions
    4. Call chain analysis
    5. Detailed code examples
  • Use Write tool to save report to log-coverage-report-YYYYMMDD-HHmmss.md

Output: Complete analysis report

Language-Specific Patterns

C/C++

Function Definition Patterns:

cpp
[return_type] [class::]function_name([parameters]) {
[\w\s:*,]*\{

Log Patterns:

  • LOG[DEIW]\(, HILOG[DEIW]\(, ALOG[DEIW]\(
  • __android_log_print
  • OHOS::HiviewDFX::HiLog::[Error|Warn|Info|Debug]

Java

Function Definition Patterns:

java
(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]\(

Python

Function Definition Patterns:

python
def\s+\w+\s*\(.*\)\s*->?\s*.*:

Log Patterns:

  • logger\.(error|warning|info|debug)\(
  • logging\.(error|warning|info|debug)\(
  • print\(

JavaScript/TypeScript

Function Definition Patterns:

javascript
function\s+\w+\s*\(.*\)\s*\{
|\w+\s*\([^)]*\)\s*(=>|\{)

Log Patterns:

  • console\.(error|warn|info|log)\(
  • logger\.(error|warn|info|debug)\(

Fix Recommendations

For Log Deficiencies

Error Return Path (Must Fix):

cpp
// 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):

cpp
// 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;
}

For High-Frequency Risks

Remove High-Frequency LOGI:

cpp
// 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:

cpp
// 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;
    }
}

Output Format

================================================================================
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:

cpp
<fixed code>

High-Frequency Risks

[High/Medium/Low] Risk

File: <file_path> Function: <function_name> Lines: <line_range> Risk:

Evidence:

cpp
<code snippet>

Analysis:

Fix:

cpp
<fixed code with throttling/statistics>

Call Chain Analysis

Call Chain: <chain_name>

<function_1>()
    ↓ [✓/✗/⚠️] <log_status>
<function_2>()
    ↓ [✓/✗/⚠️] <log_status>
<function_3>()
    ├─ [✓/✗/⚠️] branch_1
    ├─ [✓/✗/⚠️] branch_2
    └─ [✓/✗/⚠️] branch_3

Legend:

  • ✓ : Has required LOGE/LOGI
  • ✗ : Missing required logging
  • ⚠️ : Has high-frequency log risk

Recommendations

Immediate Actions (P0)

Follow-up Actions (P1)

Long-term Improvements (P2)

================================================================================


## 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

Analyze current directory

/log-coverage-analyzer

Analyze specific repository

/log-coverage-analyzer --path /path/to/repo

Analyze C++ code only

/log-coverage-analyzer --lang cpp --path /path/to/repo

Include test files in analysis

/log-coverage-analyzer --exclude-tests false

Custom output location

/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

Câu hỏi thường gặp

Kỹ năng AI Log Coverage Analyzer làm được gì?

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.)

Vì sao nên dùng Log Coverage Analyzer trên TypingMind?

Vì bạn chỉ cần cài một lần rồi dùng với bất kỳ mô hình nào. Log Coverage Analyzer là nội dung Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên cùng một kỹ năng có thể chạy trên GPT-5, Claude, Gemini, Grok hoặc mô hình trên thiết bị — và bạn có thể đổi mô hình ngay trong cuộc trò chuyện mà kỹ năng vẫn hoạt động. TypingMind dùng khóa API riêng của bạn, nên bạn thanh toán trực tiếp cho nhà cung cấp thay vì trả phí thuê bao theo suất người dùng, đồng thời kỹ năng và các cuộc trò chuyện vẫn nằm trong bộ lưu trữ của bạn.

Làm thế nào để cài Log Coverage Analyzer trong TypingMind?

Mở Plugin → Kỹ năng → Cài đặt từ GitHub trong TypingMind rồi dán https://github.com/openharmonyinsight/openharmony-skills/tree/main/skills/log-coverage-analyzer. TypingMind đọc tệp SKILL.md và cài đặt thành một kỹ năng mà bạn có thể bật cho từng cuộc trò chuyện.

Những mô hình AI nào có thể dùng Log Coverage Analyzer?

Bất kỳ mô hình nào bạn kết nối trong TypingMind. Kỹ năng AI là các hướng dẫn bằng Markdown chứ không phải mã dành riêng cho từng nhà cung cấp, nên GPT, Claude, Gemini, Grok và các mô hình chạy trên thiết bị đều có thể tải kỹ năng này khi có yêu cầu phù hợp.

Bạn có thể dùng Log Coverage Analyzer với bao nhiêu mô hình AI?

Bao nhiêu cũng được. Miễn là mô hình hỗ trợ kỹ năng, bạn có thể dùng Log Coverage Analyzer với mô hình đó — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama và nhiều mô hình khác — tất cả đều trên TypingMind với khóa API riêng của bạn.

Kỹ năng AI Log Coverage Analyzer có miễn phí không?

Có. Kỹ năng này được openharmonyinsight phát hành trên GitHub theo giấy phép MIT. Bạn chỉ trả tiền cho nhà cung cấp AI của mình theo số token đã dùng.

Kỹ năng AI là gì?

Kỹ năng AI là một gói hướng dẫn có thể tái sử dụng, chỉ cho mô hình AI cách thực hiện một tác vụ cụ thể. Kỹ năng tuân theo định dạng mở Agent Skills: một tệp SKILL.md chứa tên và mô tả, cùng các tập lệnh, mẫu hoặc tệp tham khảo mà mô hình có thể cần. Mô hình chỉ đọc hướng dẫn khi yêu cầu của bạn phù hợp với kỹ năng, nên kỹ năng đã cài đặt không phát sinh chi phí cho đến khi được sử dụng.

Kỹ năng AI khác gì với plugin hoặc máy chủ MCP?

Plugin hoặc máy chủ MCP cung cấp cho mô hình các công cụ mới để gọi — mã được chạy ở đâu đó và trả về kết quả. Còn kỹ năng AI cung cấp kiến thức và quy trình: cách tiếp cận tác vụ, các bước cần thực hiện và tiêu chí của đầu ra tốt. Kỹ năng chỉ là nội dung Markdown, nên không cần máy chủ, khóa API hay môi trường thực thi và hoạt động với mọi mô hình.

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇