# Hilog\_lite - [Introduction](#s9c9ad6e6d5494719ad0f6630a0a1add4) - [Directory Structure](#s4edd47ec6791449aa2d6362fed84325e) - [Constraints](#s7f347323ea45437ca31edae5c10f2991) - [Log Function for the Mini System](#sd6e99f792bc942f9bb5aa92111be7aff) - [Small System](#s33e0a62bc1dd4a2a9578fc22bd023f11) - [Repositories Involved](#s999c697ebde345449386ce8dc1df1db0) ## 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; ``` 1. **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"); ``` 1. **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.

2. **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 **. 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 **. 3. Parameters labeled **%\{private\}** are private data, for example, **HILOGI\("Age is %\{private\}d\\n", 10\); \>\> Age is **. 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** ![](figures/en-us_image_0000001078803238.png) 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](https://gitee.com/openharmony/docs/blob/master/en/readme/dfx.md) **hiviewdfx\_hilog\_lite** [hiviewdfx\_hiview\_lite](https://gitee.com/openharmony/hiviewdfx_hiview_lite/blob/master/README.md) [hiviewdfx\_hievent\_lite](https://gitee.com/openharmony/hiviewdfx_hievent_lite/blob/master/README.md)