• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# hilog
2
3<!--Kit: Performance Analysis Kit-->
4<!--Subsystem: HiviewDFX-->
5<!--Owner: @liuyifeifei;@buzhenwang-->
6<!--Designer: @shenchenkai-->
7<!--Tester: @liyang2235-->
8<!--Adviser: @foryourself-->
9
10HiLog is a log system that provides logging for the system framework, services, and applications to record information on user operations and system running status. You can run the hilog commands to query related log information.
11
12
13## Environment Setup
14
15- The environment for OpenHarmony Device Connector (hdc) has been set up. For details, see [Environment Setup](hdc.md#environment-setup).
16
17- The devices are properly connected and **hdc shell** is executed.
18
19<!--RP15-->
20## Overview
21
22### Log Generation
23
24If the HiLog API is called in the service code, HiLog logs are generated during service running.
25
26### Viewing Logs
27
28- Online checking:
29
30  Run the **hdc shell hilog** command.
31
32- Checking persisted files:
33
34  By default, HiLog logs are not persisted. You need to enable the persist task to persist logs to the **data/log/hilog** directory on the device. You can run the **hdc file recv data/log/hilog** command to export logs and view them locally.
35
36  For details about how to enable or disable the persist task, see [Checking and Setting Persisting Tasks](#checking-and-setting-persisting-tasks).
37
38### Log Format
39
40| Column 1| Column 2| Column 3| Column 4|  Column 5| Column 6| Column 7|
41| -------- | -------- | -------- | -------- | -------- | -------- | -------- |
42| Date| Timestamp| Process ID| Thread ID| Log level| **domainID**/Log tag:| Log content|
43| 04-19 | 17:02:14.735 | 5394 | 5394 | I | A03200/testTag: | this is a info level hilog |
44
45> **NOTE**
46>
47> Log level: **I** indicates the **Info** level. For details about other levels, see [Log Level](../reference/apis-performance-analysis-kit/capi-log-h.md#loglevel)
48>
49> **domainID**: In **A03200**, **A** indicates application logs (**LOG_APP**), and **3200** indicates that the **domainID** is **0x3200**.
50
51<!--RP15End-->
52
53## Commands
54
55<!--RP18-->
56| Short Option| Long Option| Parameter| Description|
57| -------- | -------- | -------- | -------- |
58| -h | --help | - | Shows help information.|
59| Default| Default| - | Performs a blocking read on logs, with no exiting after the read finishes.|
60| -x | --exit | - | Performs a non-blocking read on logs, with exiting after the read finishes.|
61| -a | --head | &lt;n&gt; | Shows the first several lines of logs. The parameter **\<n>** indicates the number of first lines to show.|
62| -z | --tail | &lt;n&gt; | Shows the last several lines of logs. The parameter **\<n>** indicates the number of last lines to show.|
63| -t | --type | &lt;type&gt; | Views logs of a specified type.|
64|  |  | app | Views application logs.|
65|  |  | core | Views system logs.|
66|  |  | init | Views startup logs.|
67|  |  | kmsg | Views kernel logs.|
68|  |  | only_prerelease | Views logs that are printed before the system release version. Application developers do not need to pay attention to these logs.|
69| -L | --level | &lt;level&gt; | Sets the log level, for example, **-L D/I/W/E/F**.|
70| -D | --domain | &lt;domain&gt; | Sets the domain.|
71| -T | --tag | &lt;tag&gt; | Sets the tag.|
72| -P | --pid | &lt;pid&gt; | Identifies a process.|
73| -e | --regex | &lt;expr&gt; | Prints only the lines of logs that match the regular expression specified through **\<expr>**.|
74| -v | --format | &lt;format&gt; | Sets the display format.|
75|  |  | color/colour | Displays logs in different colors. By default, logs are displayed in black and white.|
76|  |  | time | Displays the local time.|
77|  |  | epoch | Displays the amount of time elapsed since the epoch time.|
78|  |  | monotonic | Displays the amount of time elapsed since the system startup time.|
79|  |  | msec | Displays the time in milliseconds.|
80|  |  | usec | Displays the time in microseconds.|
81|  |  | nsec | Displays the time in nanoseconds.|
82|  |  | year | Displays the time with the year portion.|
83|  |  | zone | Displays the time with the local time zone.|
84|  |  | wrap | Displays logs in different lines without adding prefixes such as the timestamp to the new line.|
85|  |  | long | Displays all data fields separated by spaces.|
86| -r | - | - | Clears the buffer for logs of a specified type. This option is used together with **-t**, which specifies a log type. By default, the **app** or **core** types are used.|
87| -g | - | - | Checks the buffer size for logs of a specified type. This option is used together with **-t**, which specifies a log type. By default, the **app** or **core** types are used.|
88| -G | --buffer-size | &lt;size&gt; | Sets the size of the buffer for logs of a specified type. This option is used together with **-t**, which specifies a log type. By default, the **app** or **core** types are used. The unit can be B, KB, MB, or GB. The value ranges from 64 KB to 16 MB.|
89| -s | --statistics | - | Shows statistics. This option must be used together with **-t** or **-D**.|
90| -S | - | - | Clears statistics. This option must be used together with **-t** or **-D**.|
91| -w | --write | &lt;control&gt; | Controls a flushing task.|
92|  |  | query | Queries flushing tasks.|
93|  |  | start | Starts a flushing task. The command line parameters are the file name, size of a single file, flushing mode, and number of rotated files.|
94|  |  | stop | Stops a flushing task.|
95|  |  | refresh | Refreshes the logs in the buffer to the flushed file.|
96|  |  | clear | Deletes log files that are flushed to disks.|
97| -f | --filename | &lt;filename&gt; | Sets the names of the files to be flushed to disk.|
98| -l | --length | &lt;length&gt; | Sets the size of the files to be flushed to disk. The value must be greater than or equal to 64 KB.|
99| -n | --number | &lt;number&gt; | Sets the number of files to be flushed to disk.|
100| -m | --stream | &lt;algorithm&gt; | Sets the flushing mode.|
101|  |  | none | Indicates that data is flushed to disks in non-compression mode.|
102|  |  | zlib | Indicates that data is flushed to disks using the zlib compression algorithm. The flushed file is in .gz format.|
103| -j | --jobid | &lt;jobid&gt; | Sets the ID of a flushing task.|
104| -p | --privacy | &lt;on/off&gt; | Specifies whether to enable privacy for logs during system debugging.|
105|  |  | on | Enables privacy so that parameters are displayed as **\<private>** in printed logs.|
106|  |  | off | Disables privacy so that parameters are displayed as they are in printed logs.|
107| -k | - | &lt;on/off&gt; | Specifies whether to enable kernel logging.|
108|  |  | on | Enables kernel logging.|
109|  |  | off | Disables kernel logging.|
110| -Q | - | &lt;control-type&gt; | Controls whether to enable the default quota when the threshold is exceeded.|
111|  |  | pidon | Enables the process flow control.|
112|  |  | pidoff | Disables the process flow control.|
113|  |  | domainon | Enables the domain flow control.|
114|  |  | domainoff | Disables the domain flow control.|
115| -b | --baselevel | &lt;loglevel&gt; | Sets the lowest level of logs that can be printed: D(DEBUG)/I(INFO)/W(WARN)/E(ERROR)/F(FATAL). This command can be used together with **-D** and **-T** to set the lowest log level.|
116| - | --persist| - |Persists the log level setting command. (The setting will not be lost after the system is restarted.)|
117<!--RP18End-->
118
119
120## Displaying the Help Information
121
122```shell
123hilog -h
124```
125
126**Example**
127
128```shell
129 $ hilog -h
130 Usage:
131 -h --help
132   Show all help information.
133   Show single help information with option:
134   query/clear/buffer/stats/persist/private/kmsg/flowcontrol/baselevel/domain/combo
135 Querying logs options:
136   No option performs a blocking read and keeps printing.
137   -x --exit
138     Performs a non-blocking read and exits when all logs in buffer are printed.
139   -a <n>, --head=<n>
140     Show n lines logs on head of buffer.
141   -z <n>, --tail=<n>
142     Show n lines logs on tail of buffer.
143```
144
145## **Non-Blocking Log Reading**
146
147```shell
148hilog -x
149```
150
151**Example**
152
153<!--RP1-->
154   ```shell
155   $ hilog -x
156   11-15 15:51:02.087  2823  2823 I A01B05/AOD: AodClockFullScreen --> timeTextLineHeight:313.3333333333333 clockMarginTop:99
157   11-15 15:51:02.087  2823  2823 I A01B05/AOD: AodClockFullScreen --> timeFontSize:114.48717948717947
158   11-15 15:51:02.090  2823  2823 I A01B05/AOD: AodClockFullScreen --> timeTextWidth:202,timeTextHeight:292
159   11-15 15:51:02.100  2823  2823 I A01B05/AOD: ComponentUtil --> Component(ComponentId-AodClockNumber) draw complete.
160   11-15 15:51:02.110  1197  1197 E C01406/OHOS::RS: [LoadImgsbyResolution] Can't find resolution (1084 x 2412) in config file
161   11-15 15:51:02.127  1197  1197 E C01406/OHOS::RS: [LoadImgsbyResolution] Can't find resolution (1084 x 2412) in config file
162   ```
163<!--RP1End-->
164
165## **Viewing Logs of a Specified Level**
166
167```shell
168hilog -L D/I/W/E/F
169```
170
171**Example**
172
173<!--RP2-->
174   ```shell
175   $ hilog -L E
176   08-28 09:01:25.730  2678  2678 E A00F00/AiDataService_5.10.7.320: DataChangeNotifyManager: notifyDataChange CommonEntity no valid entity to notify
177   08-28 09:01:56.058  8560  8560 E A00500/SettingsData: DB not ready request = datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=analysis_service_switch_on , retry after DB startup
178   08-28 09:01:56.082  8560  8560 E A00500/SettingsData: decoder failure: /data/migrate/settings_global.xml , error code:-1
179   08-28 09:01:56.082  8560  8560 E A00500/SettingsData: clearXml failed:No such file or directory, error code:13900002
180   08-28 09:01:56.083  8560  8560 E A00500/SettingsData: readText failed:No such file or directory, error code:13900002
181   08-28 09:01:56.371  8586  8586 E A00500/SettingsData: DB not ready request =    datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=photo_network_connection_status , retry after DB startup
182   08-28 09:01:56.408  8586  8586 E A00500/SettingsData: decoder failure: /data/migrate/settings_global.xml , error code:-1
183   ```
184<!--RP2End-->
185
186## **Viewing Logs of a Specified Type**
187
188```shell
189hilog -t app
190```
191
192**Example**
193
194<!--RP3-->
195   ```shell
196   $ hilog -t app
197   11-15 16:04:45.903  5630  5630 I A0A5A5/Diagnosis: [DetectionFilter]820001084: switch off
198   11-15 16:04:45.905  5630  5630 I A0A5A5/Diagnosis: [DetectionFilter]847005050: frequency limit
199   11-15 16:04:45.905  5630  5630 I A0A5A5/Diagnosis: [SmartNotifyHandler]detections after filter: []
200   11-15 16:04:45.905  5630  5630 I A0A5A5/Diagnosis: [SmartNotifyHandler]no detections to detect
201   11-15 16:04:45.924  5687  5687 I A01B06/KG: MetaBalls-SystemTopPanelController --> init charging status = 3
202   ```
203<!--RP3End-->
204
205## **Viewing Logs of a Specified Domain**
206
207```shell
208hilog -D 01B06
209```
210
211**Example**
212
213<!--RP4-->
214   ```shell
215   $ hilog -D 01B06
216   11-15 16:04:54.981  5687  5687 I A01B06/KG: MetaBalls-MetaBallRenderer --> pressTime = 0 appearTime = 1731657885972
217   11-15 16:04:54.981  5687  5687 I A01B06/KG: MetaBalls-MetaBallRenderer --> backAnimator on finish
218   11-15 16:04:54.982  5687  5687 I A01B06/KG: MetaBalls-MetaBallRenderer --> setTimeout over 9s and begin animate on finish
219   11-15 16:04:55.297  5687  5687 I A01B06/KG: MetaBalls-MetaBallRenderer --> chargingTextExitAnimation onFinish
220   11-15 16:04:55.494  5687  5687 I A01B06/KG: MetaBalls-MetaBallRenderer --> uiExtension session send data success,type: exitAnimationFinish
221   ```
222<!--RP4End-->
223
224## **Viewing Logs of a Specified Domain**
225
226```shell
227hilog -T tag
228```
229
230**Example**
231
232<!--RP5-->
233   ```shell
234   $ hilog -T SAMGR
235   08-28 09:27:59.581   610 11504 I C01800/SAMGR: CommonEventCollect save extraData 1661
236   08-28 09:27:59.581   610 11504 I C01800/SAMGR: OnReceiveEvent get action: usual.event.BATTERY_CHANGED code: 0, extraDataId 1661
237   08-28 09:27:59.582   610 11504 I C01800/SAMGR: DoEvent:4 name:usual.event.BATTERY_CHANGED value:0
238   08-28 09:27:59.582   610 11504 W C01800/SAMGR: LoadSa SA:10120 AddDeath fail,cnt:1,callpid:610
239   08-28 09:27:59.583   610 11504 I C01800/SAMGR: LoadSa SA:10120 size:1,count:1
240   08-28 09:27:59.601   610 11504 I C01800/SAMGR: Scheduler SA:10120 loading
241   08-28 09:27:59.965 11518 11518 I C01800/SAMGR: SA:10120 OpenSo spend 315ms
242   08-28 09:27:59.965   610  4064 I C01800/SAMGR: AddProc:media_analysis_service. size:75
243   ```
244<!--RP5End-->
245
246## **Viewing the First n Lines of Logs in the Buffer**
247
248```shell
249hilog -a 8
250```
251
252**Example**
253
254<!--RP6-->
255   ```shell
256   $ hilog -a 8
257   11-15 16:04:08.628     0     0 I I00000/HiLog: ========Zeroth log of type: init
258   11-15 16:04:08.603   506   506 I I02C01/CustCarrierMount: MountCarrierToShared start
259   11-15 16:04:08.604   506   506 I I02C01/CustCarrierMount: success to mount carrier to shared
260   11-15 16:04:15.394   972   972 I I02C01/CustCarrierMount: UpdateCotaOpkeyLink start
261   11-15 16:04:15.396   972   972 W I02C01/CustCarrierMount: not exist CUST_GLOBAL_CARRIER_DIR or COTA_PARAM_CARRIER_DIR
262   11-15 16:04:15.887   972   972 I I02C01/CustCarrierMount: success to update cota carrier
263   11-15 16:04:48.749  5777  5901 I A00001/HiAI_Metadata: metadata is null
264   11-15 16:04:48.749  5777  5901 I A00001/HiAI_PluginAbilityInfo: abilityInfo is null
265   ```
266<!--RP6End-->
267
268## **Viewing the Last n Lines of Logs in the Buffer**
269
270```shell
271hilog -z 8
272```
273
274**Example**
275
276<!--RP7-->
277   ```shell
278   $ hilog -z 8
279   11-15 16:12:19.015  1899  7867 W C01719/ffrt: 423:FFRTQosApplyForOther:244 tid 7867, Operation not permitted, ret:-1, eno:1
280   11-15 16:12:19.125  1043  1072 I C01C42/TimeService: uid: 1010 id:428551571 name:wifi_manager_service wk:0
281   11-15 16:12:19.125  1043  1072 I C01C42/TimeService: bat: -1 id:428551571 we:505225000000 mwe:512725000000
282   11-15 16:12:19.125  1043  1072 I C01C42/TimeService: typ:3 trig: 505 225000000, bt: 495230369193
283   11-15 16:12:19.125  1043  1072 I C01C42/TimeService: cb: 428551571 ret: 0
284   11-15 16:12:19.435  3086  7813 I C01719/ffrt: 45:~WorkerThread:72 to exit, qos[3]
285   11-15 16:12:19.691   800  1404 I C01713/SUSPEND_MANAGER: [(HasSpecialStateFromBgtask):759] 20020107_com.ohos.medialibrary.medialibrarydata
286   11-15 16:12:19.691   800  1404 I C01713/SUSPEND_MANAGER: [(DozeFreezeUnit):890] Doze has special:ERR_HAS_PID_EFFICIENCY_RESOURCE
287   ```
288<!--RP7End-->
289
290## **Viewing Logs of a Specified Process**
291
292```shell
293hilog -P pid
294```
295
296**Example**
297
298<!--RP8-->
299   ```shell
300   $ hilog -P 618
301   08-28 10:19:16.872   618 17729 I C02D15/XPower: [task_52]#current system load is: 0.028767
302   08-28 10:19:23.997   618 17580 I C02D10/CpuCollector: CalculateProcessCpuStatInfos: startTime=1724811553746, endTime=1724811563996, startBootTime=47001084, endBootTime=47011335, period=10251
303   08-28 10:19:23.999   618 17580 I C02D10/CpuCollector: CollectProcessCpuStatInfos: collect process cpu statistics information size=234, isNeedUpdate=1
304   08-28 10:19:24.002   618 17580 W C01650/Rdb:  DB :
305   08-28 10:19:24.002   618 17580 W C01650/Rdb:  device: 12583051 inode: 40230 mode: 432 size: 569344 natime: Wed Aug 28 00:00:06 2024
306   08-28 10:19:24.002   618 17580 W C01650/Rdb:  smtime: Wed Aug 28 00:34:30 2024
307   08-28 10:19:24.002   618 17580 W C01650/Rdb:  sctime: Wed Aug 28 00:34:30 2024
308   ```
309<!--RP8End-->
310
311## **Viewing Logs That Match the Regular Expression Keyword**
312
313```shell
314hilog -e start
315```
316
317**Example**
318
319<!--RP9-->
320   ```shell
321   $ hilog -e start
322   11-15 16:17:17.578   547  4504 I C01800/SAMGR: AddProc start proc:media_analysis_service spend 223ms
323   11-15 16:17:17.578   547  4504 I C01800/SAMGR: Scheduler proc:media_analysis_service handle started event
324   11-15 16:17:17.578   547  4504 I C01800/SAMGR: Scheduler proc:media_analysis_service started
325   11-15 16:17:17.580  8877  8877 I C01810/SAFWK: start tasks proc:media_analysis_service end,spend 1ms
326   11-15 16:17:17.582  8877  8877 I C01651/DataShare: [operator()()-data_share_manager_impl.cpp:134]: RecoverObs start
327   11-15 16:17:17.589  8877  8893 I C01651/DataShare: [Connect()-ams_mgr_proxy.cpp:67]: connect start, uri = ******/media
328   11-15 16:17:18.225  1155  1633 I C02943/ThermalHdi: CreateLogFile start
329   11-15 16:17:18.264  1155  1633 I C02943/ThermalHdi: CompressFile start
330   ```
331<!--RP9End-->
332
333## **Viewing Logs in Different Formats**
334
335```shell
336hilog -v time/color/epoch/monotonic/usec/nsec/year/zone/wrap
337```
338
339**Example**
340
341Display the local time in nanoseconds.
342
343<!--RP10-->
344   ```shell
345   $ hilog -v time
346   11-15 16:36:21.027  1134  1723 I C02B01/HrilExt: [NotifyToBoosterTel-(hril_manager_ext.cpp:440)] RilExt:Notify to booster tel finish
347   11-15 16:36:21.027  1134  1723 I C02B01/HrilExt: [NotifyToBoosterNet-(hril_manager_ext.cpp:450)] RilExt: HNOTI_BOOSTER_NET_IND report to booster net
348   11-15 16:36:21.027  1134  1723 I C02B01/HrilExt: [NotifyToBoosterNet-(hril_manager_ext.cpp:454)] RilExt: HNOTI_BOOSTER_NET_IND report to booster net finish
349   11-15 16:36:21.027  1134  1723 I P01FFF/Rilvendor: CHAN [HandleUnsolicited] HandleUnsolicited done for modem:0, index:0, atResponse:^BOOSTERNTF: 3, 20,"0600100001000004000000000102A4FF0202F6FF"
350   11-15 16:36:21.802  2809  2831 E C02D06/XCollie: Send kick,foundation to hungtask Successful
351   11-15 16:36:21.911   882  3016 I C01F0B/TelephonyVSim: state machine ProcessEvent Id: 125
352   11-15 16:36:21.911   882  3016 I C01F0B/TelephonyVSim: StateProcess
353   ```
354
355Display the time in nanoseconds.
356
357   ```shell
358   $ hilog -v nsec
359   11-15 16:37:09.010658555  1134  1723 I C02B01/HrilExt: [BoosterRawInd-(hril_booster.cpp:296)] RilExt: BoosterRawInd
360   11-15 16:37:09.010676263  1134  1723 I C02B01/HrilExt: [BoosterRawInd-(hril_booster.cpp:328)] check need notify to satellite:indType 6
361   11-15 16:37:09.010800221  1134  1723 I C02B01/HrilExt: [NotifyToBoosterTel-(hril_manager_ext.cpp:436)] RilExt: report to telephony ext, requestNum: 4201
362   11-15 16:37:09.011011680  1134  1723 I C02B01/HrilExt: [NotifyToBoosterTel-(hril_manager_ext.cpp:440)] RilExt:Notify to booster tel finish
363   11-15 16:37:09.011064805  1134  1723 I C02B01/HrilExt: [NotifyToBoosterNet-(hril_manager_ext.cpp:450)] RilExt: HNOTI_BOOSTER_NET_IND report to booster net
364   11-15 16:37:09.011200742  1134  1723 I C02B01/HrilExt: [NotifyToBoosterNet-(hril_manager_ext.cpp:454)] RilExt: HNOTI_BOOSTER_NET_IND report to booster net finish
365   ```
366<!--RP10End-->
367
368## Checking and Setting Persisting Tasks
369
370**Viewing persist tasks**
371
372```shell
373hilog -w query
374```
375
376No persist task exists:
377
378```shell
379$ hilog -w query
380Persist task query failed
381No running persistent task [CODE: -63]
382```
383
384Persist tasks exist:
385
386```shell
387$ hilog -w query
3881 init,core,app,only_prerelease zlib /data/log/hilog/hilog 4.0M 1000
3892 kmsg zlib /data/log/hilog/hilog_kmsg 4.0M 100
390```
391
392**Enabling a persist task**
393
394> **NOTE**
395>
396> You can only enable a persist task when no persist task exists. If a persist task exists, stop it first.
397
398Enable a HiLog persist task and set the number of persist files to **1000**.
399
400```shell
401$ hilog -w start -n 1000
402Persist task [jobid:1][fileNum:1000][fileSize:4194304] start successfully
403```
404
405Enable a kmsglog persist task and set the number of persist files to **100**.
406
407```shell
408$ hilog -w start -n 100 -t kmsg
409Persist task [jobid:2][fileNum:100][fileSize:4194304] start successfully
410```
411
412When enabling a persist task, you can customize the persist rules. The compression mode can be **zlib**, **zstd**, or **none**.
413
414For example, run the following command to set the persistent file name to **kmsglog**, file size to **2 MB**, number of files to **100**, and compression mode to **zlib**:
415
416```shell
417$ hilog -w start -t kmsg -f kmsglog -l 2M -n 100 -m zlib
418Persist task [jobid:2][fileNum:100][fileSize:2097152] start successfully
419```
420
421**Disabling a persist task**
422
423Stop the current persist task:
424
425```shell
426$ hilog -w stop
427Persist task [jobid:1] stop successfully
428Persist task [jobid:2] stop successfully
429```
430
431## Displaying and Setting Log Levels
432
433**Viewing the Global Log Level**
434
435```shell
436$ param get hilog.loggable.global
437I
438```
439<!--RP17-->
440The default global log level is **INFO**.
441<!--RP17End-->
442
443<!--RP16-->
444## Setting Log Levels
445
446   ```text
447   // Set the global log level. The setting does not take effect after the device restarts.
448   hilog -b D/I/W/E/F
449
450   // Set the global log level. The setting still takes effect after the device is restarted.
451   hilog -b D/I/W/E/F --persist
452
453   // Set the log level of [DOMAINID] of the LOG_APP type.
454   hilog -b D/I/W/E/F -D 0x[DOMAINID]
455
456   // Set the log level of [TAG].
457   hilog -b D/I/W/E/F -T [TAG]
458   ```
459
460   **Example**
461
462   ```shell
463   $ hilog -b E
464   Set global log level to E successfully
465
466   $ hilog -b E --persist
467   Set global log level to E successfully
468   Set persist global log level to E successfully
469
470   $ hilog -b D -D 0x2d00
471   Set domain 0x2d00 log level to D successfully
472
473   $ hilog -b E -T testTag
474   Set tag testTag log level to E successfully
475   ```
476<!--RP16End-->
477
478## Other Common Commands
479
480### Displaying the Log Buffer Size
481
482```shell
483hilog -g
484```
485
486**Example**
487
488```shell
489$ hilog -g
490Log type app buffer size is 16.0M
491Log type init buffer size is 16.0M
492Log type core buffer size is 16.0M
493Log type only_prerelease buffer size is 16.0M
494```
495
496### Setting the Log Buffer Size
497
498```shell
499hilog -G size
500```
501
502**Example**
503
504```shell
505$ hilog -G 16M
506Set log type app buffer size to 16.0M successfully
507Set log type init buffer size to 16.0M successfully
508Set log type core buffer size to 16.0M successfully
509Set log type only_prerelease buffer size to 16.0M successfully
510```
511
512### Clearing the Log Buffer
513
514```shell
515hilog -r
516```
517
518**Example**
519
520```shell
521$ hilog -r
522Log type core,app,only_prerelease buffer clear successfully
523```
524
525### Setting Kernel Log Reading
526
527```shell
528hilog -k on/off
529```
530
531**Example**
532
533```shell
534$ hilog -k on
535Set hilogd storing kmsg log on successfully
536
537$ hilog -k off
538Set hilogd storing kmsg log off successfully
539```
540
541### Displaying Statistics
542
543```shell
544hilog -s
545```
546
547> **NOTE**
548>
549> You need to run the **param set persist.sys.hilog.stats true** command to enable the statistics functionality, and restart the device before starting statistics collection.
550
551**Example**
552
553```shell
554$ param set persist.sys.hilog.stats true
555Set parameter persist.sys.hilog.stats true success
556$ reboot
557$ hilog -s
558Log statistic report (Duration: 0h0m32s.564, From: 11-15 16:04:08.628):
559Total lines: 137517, length: 8.0M
560DEBUG lines: 0(0%), length: 0.0B(0%)
561INFO lines: 101795(74%), length: 6.1M(76%)
562WARN lines: 10268(7.5%), length: 719.9K(8.8%)
563ERROR lines: 25452(19%), length: 1.2M(15%)
564FATAL lines: 2(0.0015%), length: 259.0B(0.0031%)
565------------------------------------------------------------
566Domain Table:
567LOGTYPE- DOMAIN---- TAG----------------------------- MAX_FREQ-- TIME---------------- MAX_TP---- TIME---------------- LINES----- LENGTH---- DROPPED---
568app----- 0xf00----- -------------------------------- 924.00---- 11-15 16:04:25.594-- 111975.00- 11-15 16:04:25.594-- 3386------ 371.5K---- 0---------
569app----- 0x0------- -------------------------------- 285.00---- 11-15 16:04:34.877-- 44242.00-- 11-15 16:04:34.877-- 990------- 129.2K---- 0---------
570```
571
572**Description**
573
574```shell
575MAX_FREQ: the maximum number of log lines per second
576TIME: occurrence time
577MAX_TP: the maximum number of bytes per second
578LINES: the total number of lines in a statistical period
579LENGTH: the total number of bytes in a statistical period
580DROPPED: the number of dropped lines in a statistical period
581```
582
583### Clearing Statistics
584
585```shell
586hilog -S
587```
588
589**Example**
590
591```shell
592$ hilog -S
593Statistic info clear successfully
594```
595
596### Setting Process Flow Control
597
598```shell
599hilog -Q pidon/pidoff
600```
601
602**Example**
603
604Enable process flow control:
605
606```shell
607$ hilog -Q pidon
608Set flow control by process to enabled successfully
609```
610
611Disable process flow control:
612
613```shell
614$ hilog -Q pidoff
615Set flow control by process to disabled successfully
616```
617
618### Setting Domain Flow Control
619
620```shell
621hilog -Q domainon/domainoff
622```
623
624**Example**
625
626Enable domain flow control:
627
628```shell
629$ hilog -Q domainon
630Set flow control by domain to enabled successfully
631```
632
633Disable domain flow control:
634
635```shell
636$ hilog -Q domainoff
637Set flow control by domain to disabled successfully
638```
639
640## HiLog Flow Control Mechanism
641
642When the number of logs exceeds the upper limit, the HiLog flow control mechanism is triggered to discard excess logs and display a warning log. By default, this mechanism is disabled for debug applications.
643
644The flow control mechanism is as follows:
645
646### Application Logs
647
648The flow control is performed by process. The application logs printed in the **LOG_APP** buffer adapt to the PID flow control mechanism. When the number of logs of the **LOG_APP** type printed by a process exceeds the threshold within one second, the flow control is triggered. The following example shows the warning log:
649
650<!--RP11-->
651```text
65204-19 17:02:34.219  5394  5394 W A00032/LOGLIMIT: ==com.example.myapplication LOGS OVER PROC QUOTA, 3091 DROPPED==
653```
654<!--RP11End-->
655
656This log indicates that the number of logs printed by the **com.example.myapplication** process exceeds the threshold at **17:02:34**. In the previous second of **17:02:34.219**, 3091 lines of logs are discarded due to flow control and are not printed.
657
658**Solution**: Disable the process control mechanism by referring to [Setting Process Flow Control](#setting-process-flow-control).
659
660
661### System Logs
662
663The flow control is performed by domain ID. The system logs printed in the **LOG_CORE** buffer adapt to the domain flow control mechanism. When the number of logs of the **LOG_CORE** type printed by a domain ID exceeds the threshold within one second, the flow control is triggered. The following is an example of the warning log:
664
665<!--RP12-->
666```text
66704-19 17:02:34.219  5394  5394 W C02C02/LOGLIMIT: 108 line(s) dropped in a second!
668```
669<!--RP12End-->
670
671This log indicates that the number of logs printed by domain ID **02C02** exceeds the threshold at **17:02:34**. In the previous second of **17:02:34.219**, 108 lines of logs are discarded due to flow control and are not printed.
672
673**Solution**: Disable the domain control mechanism by referring to [Setting Domain Flow Control](#setting-domain-flow-control).
674
675
676## Handling Log Loss
677
678Currently, maintenance and debugging information is available in all log loss scenarios. You can search for the corresponding keyword in HiLog to view the causes.
679
680You can use regular expressions to search for log lines containing the keywords **LOGLIMIT**, **Slow reader missed**, and **write socket failed**.
681
682**LOGLIMIT** indicates that log loss occurs due to process or domain flow control. **Slow reader missed** indicates that global logs are lost. **write socket failed** indicates that process logs are lost.
683
684> **NOTE**
685>
686> When these messages are displayed, logs are lost and cannot be restored.
687>
688> If the log loss issue occurs in the online O&M scenario, rectify the fault by referring to the following method, reproduce the issue locally, and view the complete logs.
689
690
691### LOGLIMIT
692
693**LOGLIMIT** indicates that the number of printed logs exceeds the threshold defined by the process or domain flow control. If domain logs exceed the HiLog specifications, you must reduce and correct them at the domain level. The following is an example of the warning log:
694
695<!--RP13-->
696```text
69704-19 17:02:34.219  5394  5394 W A00032/LOGLIMIT: ==com.example.myapplication LOGS OVER PROC QUOTA, 3091 DROPPED==
698```
699<!--RP13End-->
700
701**Solution**: Disable the corresponding control mechanism by referring to [HiLog Flow Control Mechanism](#hilog-flow-control-mechanism)
702
703
704### Slow reader missed
705
706**Slow reader missed** indicates that a large number of logs are generated before and after the printing time point. As a result, the logs in the HiLog buffer are overwritten circularly before they are persisted. The following is an example of the warning log:
707
708```text
70904-19 17:02:34.219     0     0 I C00000/HiLog: ========Slow reader missed log lines: 137
710```
711
712**Cause**: Global logs are lost in any of the following situations:
713
714- The log level is set to **D**.
715
716- The flow control is disabled.
717
718- A module is repeatedly printing logs.
719
720**Solution**
721
722- Run the **hilog -g** command to query the buffer size. (The default size of the HiLog buffer is 256 KB.)
723
724- Run the **hilog -G** command to increase the HiLog buffer size. For example, run the following command to change the buffer size to 16 MB (the maximum size is 16 MB):
725
726  ```shell
727  hilog -G 16M
728  ```
729
730- Check whether logs are frequently printed in the background. If logs of a domain are frequently printed and log reading is affected, you can run the command to disable the log printing of the domain by referring to the "Solution" of **write socket failed**.
731
732
733### write socket failed
734
735**write socket failed** indicates that logs fail to be written into the socket and packet loss occurs. The following is an example of the warning log:
736
737<!--RP14-->
738```text
73904-19 17:02:34.219  5394  5394 W A00032/HiLog: write socket failed, 8 line(s) dropped!
740```
741<!--RP14End-->
742
743**Cause**: Process logs are lost in any of the following situations:
744
745- The log level is set to **D**.
746
747- The flow control is disabled.
748
749- A module is repeatedly printing logs.
750
751- If a high CPU load or insufficient memory issue occurs, the socket server processes logs slowly and logs are stacked in the socket channel. As a result, the client fails to write socket data.
752
753**Solution**: Disable the log printing of other domains and print only the logs of the current module.
754
755- Disable the log printing of other domains:
756
757  ```shell
758  hilog -b X
759  ```
760
761- Enable the log printing of the current module:
762
763  **LOG_APP**:
764
765  ```shell
766  hilog -b I -D 0x3200  (Set the log print level of the 03200 domain to INFO.)
767
768  hilog -b I -D 0x3201  (Set the log print level of the 03201 domain to INFO.)
769  ```
770
771  **LOG_CORE**:
772
773  ```shell
774  hilog -b I -D d003200  (Set the log print level of the 03200 domain to INFO.)
775
776  hilog -b I -D d003201  (Set the log print level of the 03201 domain to INFO.)
777  ```
778