bf36baa0e3 | ||
---|---|---|
.. | ||
.gitee | ||
command | ||
figures | ||
frameworks | ||
interfaces/native | ||
services | ||
LICENSE | ||
README.md | ||
README_zh.md |
README.md
Hilog_lite
- Introduction
- Directory Structure
- Constraints
- Log Function for the Mini System
- Small System
- Repositories Involved
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
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:-
**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;
-
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");
-
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
-
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.
-
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:
-
Define the log tag.
-
Perform local debugging.
The domain value **0** can be used.
-
Include the header file using #include <hilog/log.h>.
-
Add the dependency library libhilog to BUILD.gn.
API rules:
-
The format specifier is labeled public by default, for example, HILOGI("Hello World\n"); >> Hello World.
-
The formatted parameter is labeled private by default, for example, HILOGI("Age is %d\n", 10); >> Age is <private>.
-
Parameters labeled %{private} are private data, for example, HILOGI("Age is %{private}d\n", 10); >> Age is <private>.
-
Parameters labeled %{public} are public data, for example, HILOGI("Age is %{public}d\n", 10); >>Age is 10.
Parameter description
Whether the format specifier is private (Value yes means that the format specifier is private.) |
|
Viewing logs
-
Go to the /storage/data/log/ directory to view hilog logs generated during debugging.
-
Run the hilogcat command to view hilog logs in real time.
Log system architecture
-
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.
-
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.
-
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.
-
ringbuffer: configurable buffer for logs
- The ringbuffer size can be configured during compilation.
Repositories Involved
hiviwdfx_hilog_lite