niobe/base/hiviewdfx/hilog_lite
houpengfei bf36baa0e3 update OpenHarmony 3.0 LTS 2021-10-22 13:59:18 +08:00
..
.gitee init 2021-09-22 21:52:48 +08:00
command update OpenHarmony 3.0 LTS 2021-10-22 13:59:18 +08:00
figures init 2021-09-22 21:52:48 +08:00
frameworks update OpenHarmony 3.0 LTS 2021-10-22 13:59:18 +08:00
interfaces/native update OpenHarmony 3.0 LTS 2021-10-22 13:59:18 +08:00
services update OpenHarmony 3.0 LTS 2021-10-22 13:59:18 +08:00
LICENSE update OpenHarmony 3.0 LTS 2021-10-22 13:59:18 +08:00
README.md init 2021-09-22 21:52:48 +08:00
README_zh.md init 2021-09-22 21:52:48 +08:00

README.md

Hilog_lite

Introduction

Hilog_lite provides the log function of the DFX subsystem for the mini and small systems.

Directory Structure

Table 1 Directory structure for Hilog_lite in the DFX subsystem

Directory

Description

interfaces/native/kits/hilog

Defines external APIs that provide the log function for the small system.

interfaces/native/kits/hilog_lite

Defines external APIs that provide the log function for the mini system.

services/hilogcat

Stores log-related services and commands for the small system.

services/apphilogcat

Provides the log flushing service for the small system.

command

Provides log query commands for the mini system.

frameworks/featured

Implements the APIs that provide the log function for the small system.

frameworks/mini

Implements the APIs that provide the log function for the mini system.

Constraints

The overall code of the mini system is developed based on the C standard library.

Log Function for the Mini System

  • To add a module for example, Module A and print logs, perform the following steps:
    1. **Add the module ID. **

      Add HILOG_MODULE_A to base/hiviewdfx/interfaces/hilog_lite/interfaces/native/kits/hilog_lite.

      typedef enum {
          /** DFX */    
          HILOG_MODULE_HIVIEW = 0,    
          /** System Module A */    
          HILOG_MODULE_A,    
          /** Maximum number of modules */
          HILOG_MODULE_MAX
      } HiLogModuleType;
      
    2. Register the module.

      Add the following code to the initialization process of Module A to register it with the log framework:

      HiLogRegisterModule(HILOG_MODULE_A, "A");
      
    3. Modify the static configuration of the DFX framework.

      Modify g_hiviewConfig in the following file as required. By default, modification is not required and logs are output to the serial port.

      utils/lite/hiview_config.c
      

      Configuration Item

      Description

      outputOption

      Log output mode. The value can be:

      • OUTPUT_OPTION_DEBUG: Logs are directly output to the serial port without cross-task scheduling. This value is used only for temporary debugging.
      • OUTPUT_OPTION_FLOW (default value): Logs are output as data flow to the serial port.
      • OUTPUT_OPTION_TEXT_FILE: Logs are output as text files.

      level

      Log level for output. Only the logs whose levels are higher than or equal to the level specified by this parameter can be output. The value can be HILOG_LV_DEBUG, HILOG_LV_INFO, HILOG_LV_WARN, HILOG_LV_ERROR, or HILOG_LV_FATAL.

      logSwitch

      Log switch. The HiLog module can be successfully initialized even if this switch is turned off before compilation. By default, this switch is turned on. The value can be HIVIEW_FEATURE_ON or HIVIEW_FEATURE_OFF.

      dumpSwitch

      Dump switch. If this switch is turned off before compilation, the HiDumper module will not be initialized. By default, this switch is turned off. The value can be HIVIEW_FEATURE_ON or HIVIEW_FEATURE_OFF.

      eventSwitch

      Event output switch. If this switch is turned off before compilation, the HiEvent module will not be initialized. By default, this switch is turned off. The value can be HIVIEW_FEATURE_ON or HIVIEW_FEATURE_OFF.

    4. Print logs.

      Include #include "log.h" in the .c file where logs need to be printed. Call the following API:

      HILOG_INFO(HILOG_MODULE_A, "log test: %d", 88);

      The following table describes the parameters in the API.

      Parameter

      Mandatory

      Data Type

      Description

      mod

      Yes

      uint8

      Module or service ID.

      IDs are planned and allocated in a unified manner. A maximum of 64 IDs are supported. Third-party applications use HILOG_MODULE_APP as their module ID.

      fmt

      Yes

      char *

      Format specifier for output.

      1. A maximum of six variable parameters are supported. %s is not supported.

      2. The maximum length of a formatted log record is 128 bytes. If the maximum length is exceeded, new logs cannot be printed.

      Variable parameters

      No

      int32

      Variable parameters. Only numeric types are supported. A maximum of six variable parameters are allowed.

Small System

Native C and C++ APIs

Available HiLog APIs are as follows:

HILOG_DEBUG(type, ...)
HILOG_INFO(type, ...)
HILOG_WARN(type, ...)
HILOG_ERROR(type, ...)
HILOG_FATAL(type, ...)

Usage guidelines:

  1. Define the log tag.

  2. Perform local debugging. The domain value **0** can be used.

  3. Include the header file using #include <hilog/log.h>.

  4. Add the dependency library libhilog to BUILD.gn.

API rules:

  1. The format specifier is labeled public by default, for example, HILOGI("Hello World\n"); >> Hello World.

  2. The formatted parameter is labeled private by default, for example, HILOGI("Age is %d\n", 10); >> Age is <private>.

  3. Parameters labeled %{private} are private data, for example, HILOGI("Age is %{private}d\n", 10); >> Age is <private>.

  4. Parameters labeled %{public} are public data, for example, HILOGI("Age is %{public}d\n", 10); >>Age is 10.

Parameter description

Parameter

Description

domain

Domain ID

tag

Log tag

isFmtPrivate

Whether the format specifier is private (Value yes means that the format specifier is private.)

fmt

Format specifier

args

Parameters to be displayed using the format specifier

Viewing logs

  1. Go to the /storage/data/log/ directory to view hilog logs generated during debugging.

  2. Run the hilogcat command to view hilog logs in real time.

Log system architecture

  1. hilogtask: log task in the kernel

    • This is a task or thread of the Linux kernel. It is initialized during system startup.
    • When a module in the kernel calls the log API, the formatted log content is transferred to the task and stored in a ringbuffer.
    • When the log API is called in the user space, the formatted log content is written into the driver node by calling ioctl. The driver node then sends the log content to hilogtask, and hilogtask stores the log content in the ringbuffer.
  2. hilogcatd: storage for logs in user space

    • This is a user-space process. It periodically reads the log content from the ringbuffer and stores it in the log file.
    • Log files can be compressed in gzip format by using zlib.
    • The size of a single file and the number of files can be configured during compilation.
  3. hilogcat: command line tool for viewing logs

    This tool reads the log content in the ringbuffer via the kernel driver API, and then outputs the content to stdout.

  4. ringbuffer: configurable buffer for logs

    • The ringbuffer size can be configured during compilation.

Repositories Involved

DFX subsystem

hiviwdfx_hilog_lite

hiviwdfx_hiview_lite

hiviwdfx_hievent_lite