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.
Download the HarmonyOS SDK. By default, you can obtain hilogtool from the hms/toolchains directory of the corresponding OS (Windows/Linux/macOS).
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
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
Press i to enter Insert mode.
Enter the following information to add the PATH information.
export PATH=$PATH:/path/to/your/hilogtool
Press Esc to exit Insert mode. Then enter :wq and press Enter to save the settings.
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
After the environment variable configuration is finished, restart the PC.
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 |
Log parsing may fail if the data dictionary is missing. Restart the device to regenerate a data dictionary.
In the current log directory, enter the shell window through the cmd window. In the shell window, run the hilogtool parse command to parse the log files, as shown in the following figure.
hilogtool parse -i D:\09-temp\dict-test -d D:\09-temp\dict-test
hilogtool parse -i D:\09-temp\dict-test\hilog.025.20231020-154659.gz -d D:\09-temp\dict-test
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.
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
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
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.
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.
| 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 |
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
The parsing command is incorrect. For details, see Common Parsing Commands.
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.
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.