目录

hilogtool

Application scenarios

Currently, HiLog files are encoded in binary and saved in .gz format, which cannot be directly decompressed or downloaded after being exported from the /data/log/hilog directory of the device. With hilogtool, you can easily decompress the log files and convert them into plaintext.

In the current mechanism, kmsg logs are not affected and can be viewed directly; the HiLog files can be viewed online by running the hilog command in the shell window.

Usage

[h2]How to Obtain

Download the HarmonyOS SDK. By default, you can obtain hilogtool from the hms/toolchains directory of the corresponding OS (Windows/Linux/macOS).

[h2]Environment Configuration

For Windows

Choose This computer > properties > advanced system settings > advanced > environment variables > Path > Edit. Add the path of hilogtool.exe to Path. After that, restart the PC, and run the hilogtool command in the cmd window.

For MacOS

  1. Start the terminal tool and run the following command:

    echo $SHELL

    If the command output is /bin/bash, open the .bash_profile file.

    vi ~/.bash_profile

    If the command output is /bin/zsh, open the .zshrc file.

    vi ~/.zshrc
  2. Press i to enter Insert mode.

  3. Enter the following information to add the PATH information.

    export PATH=$PATH:/path/to/your/hilogtool
  4. Press Esc to exit Insert mode. Then enter :wq and press Enter to save the settings.

  5. Run the following command for the environment variable to take effect.

    If the .bash_profile file is opened in step 1, run the following command:

    source ~/.bash_profile

    If the .zshrc file is opened in 1, run the following command:

    source ~/.zshrc
  6. After the environment variable configuration is finished, restart the PC.

[h2]Instructions

Command:

hilogtool parse -i xxx -o xxx -d xxx

hilogtool parse --input xxx --output xxx --dict xxx

Parse command parameters:

Option Description Example
-h/--help Displays the help information. hilogtool -h
-i/–-input inputDir

Specifies the input path. All HiLog files in the directory are scanned and parsed.

By default, it is the current command path.

Parse all HiLog files in the D:\temp\hilog directory:

hilogtool parse -i D:\temp\hilog

Parse all HiLog files in the current directory:

hilogtool parse -i .\

-i/–-input inputFile Parses a specified HiLog file.

Parse a specified HiLog file:

hilogtool parse -i D:\temp\data\log\hilog.706.20230711-071816.gz

hilogtool parse -i .\hilog.706.20230711-071816.gz

-o/–-output outputDir

Specifies the output path, which is the path for saving parsed log files.

The default value is the path of the parsed original HiLog file.

Parse the log files in the current directory to the D:\temp directory:

hilogtool parse -i .\ -o D:\temp

-d/--dict dictFile

Specifies the path of the data dictionary.

By default, the latest data dictionary file (for example, hilog_dict.20230908-142200.zip) is matched in the current command path.

Parse all HiLog files in the D:\temp\hilog directory and specify the data dictionary in the directory.

hilogtool parse -i D:\temp\hilog -d D:\temp\hilog\hilog_dict.20230908-142200.zip

-v/--version Checks the current version. hilogtool -v
  1. The data dictionary file is stored in the data/log/hilog directory and named in the format of hilog_dict.2024xxxx-xxxxxx.zip. The file is automatically generated when the device is started and is required for parsing logs.

Log parsing may fail if the data dictionary is missing. Restart the device to regenerate a data dictionary.

  1. The default format of the flushed HiLog log file is hilog\.\d{3}\.\d{8}-\d{6}\.gz$. If the file name is customized by running the hilog\.\d{3}\.\d{8}-\d{6}.gz$ command during development, the log file may fail to be parsed. To resolve this problem, upgrade hilogtool to 1.0.0b or later.

Common Parsing Commands

[h2]Parsing HiLog Files in the Specified Directory

hilogtool parse -i D:\09-temp\dict-test -d D:\09-temp\dict-test

[h2]Parsing a Single HiLog File

hilogtool parse -i D:\09-temp\dict-test\hilog.025.20231020-154659.gz -d D:\09-temp\dict-test

Automatic Scripts

The automatic script is named get_hilog.bat. Place it in the same directory as hilogtool. The script exports logs in the data/log/hilog from the device and automatically converts the logs to plaintext.

[h2]For Windows

The get_hilog.bat script on Windows is as follows:

@set Ymd=%date:~0,4%_%date:~5,2%%date:~8,2%_%time:~0,2%%time:~3,2%%time:~6,2%
@set Ymd=%Ymd: =0%
@set Dir=LOG_%YMD%
md %Dir%
hdc file recv /data/log/hilog/ .\%Dir%\
hilogtool parse -i .\%Dir% -d .\%Dir%
pause

[h2]For macOS

The script on macOS is as follows:

Ymd=$(date "+%Y_%m%d_%H%M%S")
Dir=LOG_$Ymd
mkdir $Dir
hdc file recv /data/log/hilog/ ./$Dir/
./hilogtool parse -i ./$Dir -d ./$Dir

Scenarios That May be Affected

[h2]Automatic Log Analysis

In some domains, automatic analysis is required for plaintext log files in the /data/log/hilog directory. As HiLog uses the lightweight implementation, logs are saved in the binary format. Therefore, hilogtool needs to be adapted for automatic decompilation of binary logs.

[h2]Log Forwarding

The log files obtained from the /data/log/hilog directory of the device by using recv are in the binary format and cannot be viewed directly. You are advised to parse the log files before sending them, or forward the binary log files together with the data dictionary.

Error Code

Result Code Description Handling Method
200 Decoding is successful. N/A
300 Decoding failed because logs in some domains do not match the dictionary.

1. If only some logs fail to be parsed, the problem does not affect self-debugging and can be ignored.

2. If the self-debugging is affected, generate the data dictionary incrementally by referring to the following FAQs.

500 The parsing tool version does not match. Update the version of hilogtool.
999 The log is saved in plaintext and does not require parsing. N/A

FAQs

Problem

During parsing, "there is no hilog dict zip in xxx, use -d to specify", or "open dict xxx fail, errno is: No such file or directory" is displayed.

In the parsed log, "OpenUuidFile fail, unknown log, uuid is: xxxxxx" is displayed.

Possible causes

The corresponding data dictionary is not found during log parsing.

Answer

  1. The parsing command is incorrect. For details, see Common Parsing Commands.

  2. The bin/so file is replaced locally for debugging. In such a case, a new data dictionary needs to be generated for parsing by performing one of the following operations:

(1) Run the hilog -d xxx command to incrementally generate a data dictionary.

For example, push the hilogTest file (.bin file) to the /system/bin/ directory. Then, run the following command to incrementally generate the data dictionary of hilogTest:

hdc shell hilog -d /system/bin/hilogTest

After the data dictionary is successfully generated, the hilogTest can print logs.

(2) Restart hilogd: service_control stop hilogd && service_control start hilogd

(3) Restart the device.

  1. The data dictionary is deleted. Check whether the exported logs contain data dictionary files named in the format of hilog_dict.2024xxxx-xxxxxx.zip.

If there is no such a data dictionary, it is possibly deleted by running the rm -rf data/log/hilog/* command. In this case, restart the device to generate a new data dictionary.