faqs-dfx.md 5.5 KB
Newer Older
S
shawn_he 已提交
1 2
# DFX Development

S
shawn_he 已提交
3
## How do I flush HiLog information to disks?
S
shawn_he 已提交
4

S
shawn_he 已提交
5
Applicable to: OpenHarmony 3.2 Beta (API version 9) 
S
shawn_he 已提交
6

S
shawn_he 已提交
7
**Solution**
S
shawn_he 已提交
8

S
shawn_he 已提交
9
Run the **hilog -w start -f ckTest -l 1M -n 5 -m zlib -j 11** command.
S
shawn_he 已提交
10

S
shawn_he 已提交
11
The log file is saved in the **/data/log/hilog/** directory.
S
shawn_he 已提交
12

S
shawn_he 已提交
13
**Parameters:**
S
shawn_he 已提交
14

S
shawn_he 已提交
15 16 17 18 19 20 21 22 23
```
-**-w**: Starts a log flushing task. **start** means to start the task, and **stop** means to stop the task.
-**-f**: Sets the log file name.
-**-l**: Sets the size of a single log file. The unit can be B, KB, MB, or GB.
-**-n**: Sets the maximum number of log files. When the number of log files exceeds the specified value, the earliest log file will be overwritten. The value range is [2,1000].
-**-m**: Specifies the log file compression algorithm.
-**-j**: Specifies the task ID. The value ranges from **10** to **0xffffffffff**.
For more details about parameters, run the **hilog --help** command.
```
S
shawn_he 已提交
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149

## How do I print only HiLog information of the current application?

Applicable to: OpenHarmony 3.2 Beta (API version 9) 

**Solution**

Use the hilog command line tool to filter the logs of the current application.

**hilog -T xxx**: filtering logs by tag.

**hilog –D xxx**: filtering logs by domain.

**hilog -e**: matching log content based on the tag, domain, and pid by using regular expressions. Multi-layered filtering, combination filtering, and reverse filtering are supported.

## How do I locate the fault when the application crashes?

Applicable to: OpenHarmony 3.2 Beta (API version 9) 

**Solution**

Method 1: Locate the crash-related code based on the service log.

Method 2: View the error information in the crash file. The crash file is located at **/data/log/faultlog/faultlogger/**.

## Is HiLog or console recommended for log printing? How do I set the domain if HiLog is used?

Applicable to: OpenHarmony 3.2 Beta (API version 9) 

The console encapsulates the HiLog system with the default parameter configuration. It is mainly used in the application development and debugging phase.

HiLog is recommended because it supports log classification and processing in a unified manner. For details, see [@ohos.hilog (HiLog)](../reference/apis/js-apis-hilog.md#hilogisloggable).

The value of the **domain** parameter in the HiLog API ranges from **0x0** to **0xFFFF**. You are advised to customize the value as required.

## What is the maximum length of a log record when HiLog Is used? Is it configurable?

Applicable to: OpenHarmony 3.2 Beta (API version 9) 

The maximum length of a log record is 1,024 characters, and it is not changeable.

## What is the purpose of using private in printing of formatted logs?

Applicable to: OpenHarmony 3.2 Beta (API version 9)

**Symptom**

**private** is displayed in HiLog information when format parameters are of the %d or %s type in C++.

**Solution**

When format parameters such as **%d** and **%s** are directly used, the standard system uses **private** to replace the actual data for printing by default to prevent data leakage. To print the actual data, replace **%d** with **%{public}d** or replace **%s** with **%{public}s**.

## What should I do if the hilog.debug log cannot be printed?

Applicable to: OpenHarmony 3.2 Beta (API version 9)

**Solution**

Run **hdc std shell hilog -b D** to turn on the debugging switch.

## Can I separate multiple strings by spaces in the tag parameter of the HiLog API?

Applicable to: OpenHarmony 3.2 Beta (API version 9)

Yes.

## How does HiLog print the log information marked with the \{private\} tag?

Applicable to: OpenHarmony 3.2 Beta (API version 9)

**Solution**

To print the log information marked with the \{private\} tag, run the command to disable the privacy mode: hdc shell hilog -p off

## What are the cash log collection and performance troubleshooting functions provided by the HiLog system?

Applicable to: OpenHarmony 3.2 Beta (API version 9)

**Symptom**

What are the cash log collection and performance troubleshooting functions provided by the HiLog system?

**Solution**

FaultLogger: collects crash logs. For details, see [FaultLogger](../reference/apis/js-apis-faultLogger.md).

HiChecker: detects potential faults. For details, see [HiChecker](../reference/apis/js-apis-hichecker.md).

hiTraceMeter: implements performance tracing. For details, see [hiTraceMeter](../reference/apis/js-apis-hitracemeter.md).

## How do I control log output?

Applicable to: OpenHarmony 3.2 Beta (API version 9)

**Symptom**

The output log varies according to environment requirements.

**Solution**

You can run the following command to adjust the log level to print the desired logs:  

hdc shell hilog -L <D/I/W/E/F\>

## Is there a limit on the tag length of HiLog?

Applicable to: OpenHarmony 3.2 Beta (API version 9)

The length of the entire tag is 32.

## How do I view the appfreeze information in the logs?

Applicable to: OpenHarmony 3.2 Beta (API version 9)

Try the following procedure:

1. Check the reason for the event. Fault location methods and examples are provided specifically to different reasons.

2. Check the MSG information.

3. Check the application stack information in OpenStacktraceCatcher as well as the HiLog information for the operation that leads to the event.

4. Check the PeerBinderCatcher process to see if the current process is suspended by the peer binder. If there is a synchronous wait related to the current process, the corresponding PeerBinder Stacktrace information will be logged. It contains the stack information of the peer process that leads to suspension of the current process.

5. Check the CPU usage of system processes and the memory usage of the current process.