1# hilog
2
3
4HiLog 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.
5
6
7## Prerequisites
8
9- The environment for OpenHarmony Device Connector (hdc) has been set up. For details, see [Environment Setup](hdc.md#environment-setup).
10
11- The devices are properly connected.
12
13
14## Commands
15
16The table below lists the available **hilog** command line options.
17
18| Short Option| Long Option| Parameter| Description|
19| -------- | -------- | -------- | -------- |
20| -h | --help |  | Shows help information.|
21| Default| Default|  | Performs a blocking read on logs, with no exiting after the read finishes.|
22| -x | --exit |  | Performs a non-blocking read on logs, with exiting after the read finishes.|
23| -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.|
24| -G | --buffer-size | <size> | 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.|
25| -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.|
26| <!--DelRow-->-p | --privacy | &lt;on/off&gt; | Specifies whether to enable privacy for logs during system debugging.|
27| <!--DelRow--> |  | on | Enables privacy so that parameters are displayed as **\<private>** in printed logs.|
28| <!--DelRow--> |  | off | Disables privacy so that parameters are displayed as they are in printed logs.|
29| -k |  | &lt;on/off&gt; | Specifies whether to enable kernel logging.|
30|  |  | on | Enables kernel logging.|
31|  |  | off | Disables kernel logging.|
32| -s | --statistics |  | Shows statistics. This option must be used together with **-t** or **-D**.|
33| -S |  |  | Clears statistics. This option must be used together with **-t** or **-D**.|
34| -Q |  | &lt;control-type&gt; | Specifies whether to enable the default quota for flow control.|
35|  |  | pidon | Enables process flow control.|
36|  |  | pidoff | Disables process flow control.|
37|  |  | domainon | Enables domain flow control.|
38|  |  | domainoff | Disables domain flow control.|
39| -L | --level | &lt;level&gt; | Sets the log level, for example, **-L D/I/W/E/F**.|
40| -t | --type | &lt;type&gt; | Sets the log type, for example, **-t app core init**.|
41| -D | --domain | &lt;domain&gt; | Sets the domain.|
42| -T | --tag | &lt;tag&gt; | Sets the tag.|
43| -a | --head | &lt;n&gt; | Shows the first several lines of logs.The parameter **\<n>** indicates the number of first lines to show.|
44| -z | --tail | &lt;n&gt; | Shows the last several lines of logs.The parameter **\<n>** indicates the number of last lines to show.|
45| -P | --pid | &lt;pid&gt; | Identifies a process.|
46| -e | --regex | &lt;expr&gt; | Prints only the lines of logs that match the regular expression specified through **\<expr>**.|
47| -f | --filename | &lt;filename&gt; | Sets the names of the files to be flushed to disk.|
48| -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.|
49| -n | --number | &lt;number&gt; | Sets the number of files to be flushed to disk.|
50| -j | --jobid | &lt;jobid&gt; | Sets the ID of a flushing task.|
51| -w | --write | &lt;control&gt; | Controls a flushing task.|
52|  |  | query | Queries flushing tasks.|
53|  |  | 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.|
54|  |  | stop | Stops a flushing task.|
55|  |  | refresh | Refreshes the logs in the buffer to the flushed file.|
56|  |  | clear | Deletes log files that are flushed to disks.|
57| -m | --stream | &lt;algorithm&gt; | Sets the flushing mode.|
58|  |  | none | Indicates that data is flushed to disks in non-compression mode.|
59|  |  | zlib | Indicates that data is flushed to disks using the zlib compression algorithm. The flushed file is in .gz format.|
60|  |  | zstd | Indicates that data is flushed to disks using the zstd compression algorithm. The flushed file is in .zst format.|
61| -v | --format | &lt;format&gt; |  |
62|  |  | time | Displays the local time.|
63|  |  | color | Adds colors to logs at different levels. By default, logs are displayed in black and white.|
64|  |  | epoch | Displays the amount of time elapsed since the epoch time.|
65|  |  | monotonic | Displays the amount of time elapsed since the system startup time.|
66|  |  | usec | Displays the time in microseconds.|
67|  |  | nsec | Displays the time in nanoseconds.|
68|  |  | year | Displays the time with the year portion.|
69|  |  | zone | Displays the time with the local time zone.|
70| -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).|
71
72## Examples
73
74### Display the help information.
75
76   ```
77   hilog -h
78   ```
79
80   **Example**
81
82   ```
83    $ hilog -h
84    Usage:
85    -h --help
86      Show all help information.
87      Show single help information with option:
88      query/clear/buffer/stats/persist/private/kmsg/flowcontrol/baselevel/domain/combo
89    Querying logs options:
90      No option performs a blocking read and keeps printing.
91      -x --exit
92        Performs a non-blocking read and exits when all logs in buffer are printed.
93      -a <n>, --head=<n>
94        Show n lines logs on head of buffer.
95      -z <n>, --tail=<n>
96        Show n lines logs on tail of buffer.
97   ```
98
99### Display the size of the log buffer.
100
101   ```
102   hilog -g
103   ```
104
105   **Example**
106
107   ```
108   $ hilog -g
109   Log type app buffer size is 16.0M
110   Log type init buffer size is 16.0M
111   Log type core buffer size is 16.0M
112   Log type only_prerelease buffer size is 16.0M
113   ```
114
115### Change the size of the log buffer.
116
117   ```
118   hilog -G size
119   ```
120
121   **Example**
122   ```
123   $ hilog -G 16M
124   Set log type app buffer size to 16.0M successfully
125   Set log type init buffer size to 16.0M successfully
126   Set log type core buffer size to 16.0M successfully
127   Set log type only_prerelease buffer size to 16.0M successfully
128   ```
129
130### Enable/Disable process flow control.
131
132   ```
133   hilog -Q pidon/pidoff
134   ```
135
136
137   **Example**
138
139   ```
140   $ hilog -Q pidon
141   Set flow control by process to enabled successfully
142   $
143   $ hilog -Q pidoff
144   Set flow control by process to disabled successfully
145   ```
146
147### Enable/Disable domain flow control.
148
149   ```
150   hilog -Q domainon/domainoff
151   ```
152
153   **Example**
154
155   ```
156   $ hilog -Q domainon
157   Set flow control by domain to enabled successfully
158   $
159   $ hilog -Q domainoff
160   Set flow control by domain to disabled successfully
161   ```
162
163### Display logs of a specified level.
164
165   ```
166   hilog -L D/I/W/E/F
167   ```
168
169   **Example**
170
171   ```
172   $ hilog -L E
173   08-28 09:01:25.730  2678  2678 E A00F00/com.huawei.hmos.aidataservice/AiDataService_5.10.7.320: DataChangeNotifyManager: notifyDataChange CommonEntity no valid entity to notify
174   08-28 09:01:56.058  8560  8560 E A00500/com.ohos.settingsdata/SettingsData: DB not ready request = datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=analysis_service_switch_on , retry after DB startup
175   08-28 09:01:56.082  8560  8560 E A00500/com.ohos.settingsdata/SettingsData: decoder failure: /data/migrate/settings_global.xml , error code:-1
176   08-28 09:01:56.082  8560  8560 E A00500/com.ohos.settingsdata/SettingsData: clearXml failed:No such file or directory, error code:13900002
177   08-28 09:01:56.083  8560  8560 E A00500/com.ohos.settingsdata/SettingsData: readText failed:No such file or directory, error code:13900002
178   08-28 09:01:56.371  8586  8586 E A00500/com.ohos.settingsdata/SettingsData: DB not ready request =    datashare:///com.ohos.settingsdata/entry/settingsdata/SETTINGSDATA?Proxy=true&key=photo_network_connection_status , retry after DB startup
179   08-28 09:01:56.408  8586  8586 E A00500/com.ohos.settingsdata/SettingsData: decoder failure: /data/migrate/settings_global.xml , error code:-1
180   ```
181
182### Display logs of a specified tag.
183
184   ```
185   hilog -T tag
186   ```
187
188   **Example**
189
190   ```
191   $ hilog -T SAMGR
192   08-28 09:27:59.581   610 11504 I C01800/samgr/SAMGR: CommonEventCollect save extraData 1661
193   08-28 09:27:59.581   610 11504 I C01800/samgr/SAMGR: OnReceiveEvent get action: usual.event.BATTERY_CHANGED code: 0, extraDataId 1661
194   08-28 09:27:59.582   610 11504 I C01800/samgr/SAMGR: DoEvent:4 name:usual.event.BATTERY_CHANGED value:0
195   08-28 09:27:59.582   610 11504 W C01800/samgr/SAMGR: LoadSa SA:10120 AddDeath fail,cnt:1,callpid:610
196   08-28 09:27:59.583   610 11504 I C01800/samgr/SAMGR: LoadSa SA:10120 size:1,count:1
197   08-28 09:27:59.601   610 11504 I C01800/samgr/SAMGR: Scheduler SA:10120 loading
198   08-28 09:27:59.965 11518 11518 I C01800/media_analysis_service/SAMGR: SA:10120 OpenSo spend 315ms
199   08-28 09:27:59.965   610  4064 I C01800/samgr/SAMGR: AddProc:media_analysis_service. size:75
200   ```
201
202### Display logs of a specified process.
203
204   ```
205   hilog -P pid
206   ```
207
208   **Example**
209
210   ```
211   $ hilog -P 618
212   08-28 10:19:16.872   618 17729 I C02D15/hiview/XPower: [task_52]#current system load is: 0.028767
213   08-28 10:19:23.997   618 17580 I C02D10/hiview/CpuCollector: CalculateProcessCpuStatInfos: startTime=1724811553746, endTime=1724811563996, startBootTime=47001084, endBootTime=47011335, period=10251
214   08-28 10:19:23.999   618 17580 I C02D10/hiview/CpuCollector: CollectProcessCpuStatInfos: collect process cpu statistics information size=234, isNeedUpdate=1
215   08-28 10:19:24.002   618 17580 W C01650/hiview/Rdb:  DB :
216   08-28 10:19:24.002   618 17580 W C01650/hiview/Rdb:  device: 12583051 inode: 40230 mode: 432 size: 569344 natime: Wed Aug 28 00:00:06 2024
217   08-28 10:19:24.002   618 17580 W C01650/hiview/Rdb:  smtime: Wed Aug 28 00:34:30 2024
218   08-28 10:19:24.002   618 17580 W C01650/hiview/Rdb:  sctime: Wed Aug 28 00:34:30 2024
219   ```
220
221### Display and set flushing tasks
222
223   ```
224   hilog -w control
225   ```
226
227   > **NOTE**
228   >
229   > Run **hilog -w query** to query the current task.
230   >
231   > Run **hilog -w start -n 1000** to start the HiLog flushing task and set the number of flushed files to **1000**.
232   >
233   > Run **hilog -w start -n 100 -t kmsg** to start the kmsglog flushing task and set the number of flushed files to **100**.
234   >
235   > Run hilog -w stop to stop the flushing task.
236
237   **Example**
238
239   ```
240   $ hilog -w query
241   Persist task query failed
242   No running persistent task [CODE: -63]
243   $
244   $ hilog -w start -n 1000
245   Persist task [jobid:1][fileNum:1000][fileSize:4194304] start successfully
246   $
247   $ hilog -w start -n 100 -t kmsg
248   Persist task [jobid:2][fileNum:100][fileSize:4194304] start successfully
249   $
250   $ hilog -w stop
251   Persist task [jobid:1] stop successfully
252   Persist task [jobid:2] stop successfully
253   ```
254
255### Set the lowest level of logs that can be printed
256
257   ```
258   hilog -b D/I/W/E/F
259   ```
260
261   **Example**
262
263   ```
264   $ hilog -b E
265   Set global log level to E successfully
266   ```
267<!--Del-->
268### Enable/Disable the privacy format.
269
270   ```
271   hilog -p on/off
272   ```
273
274   **Example**
275
276   ```
277   # hilog -p on
278   Set hilog privacy format on successfully
279   #
280   # hilog -p off
281   Set hilog privacy format off successfully
282   ```
283<!--DelEnd-->
284