1# hilog 2 3 4HiLog日志系统,提供给系统框架、服务、以及应用,用于打印日志,记录用户操作、系统运行状态等。开发者可以通过hilog命令行查询相关日志信息。 5 6 7## 前置条件 8 9- 根据hdc命令行工具指导,完成[环境准备](hdc.md#环境准备)。 10 11- 正常连接设备。 12 13 14## 命令行说明 15 16hilog命令行使用方式: 17 18| 短选项 | 长选项 | 参数 | 说明 | 19| -------- | -------- | -------- | -------- | 20| -h | --help | | 帮助命令。 | 21| 缺省 | 缺省 | | 阻塞读日志,不退出。 | 22| -x | --exit | | 非阻塞读日志,读完退出。 | 23| -g | | | 查询buffer的大小,配合-t指定某一类型使用,默认app和core。 | 24| -G | --buffer-size | <size> | 设置指定<type>日志类型缓冲区的大小,配合-t指定某一类型使用,默认app和core, 可使用B/K/M为单位,范围为64K-16M。 | 25| -r | | | 清除buffer日志,配合-t指定某一类型使用,默认app和core。 | 26| <!--DelRow-->-p | --privacy | <on/off> | 支持系统调试时日志隐私开关控制。 | 27| <!--DelRow--> | | on | 打开隐私开关,显示<private>。 | 28| <!--DelRow--> | | off | 关闭隐私开关,显示明文。 | 29| -k | | <on/off> | Kernel日志读取开关控制。 | 30| | | on | 打开读取kernel日志。 | 31| | | off | 关闭读取kernel日志。 | 32| -s | --statistics | | 查询统计信息,需配合-t或-D使用。 | 33| -S | | | 清除统计信息,需配合-t或-D使用。 | 34| -Q | | <control-type> | 流控缺省配额开关控制。 | 35| | | pidon | 进程流控开关打开。 | 36| | | pidoff | 进程流控开关关闭。 | 37| | | domainon | domain流控开关打开。 | 38| | | domainoff | domain流控开关关闭。 | 39| -L | --level | <level> | 指定级别的日志,示例:-L D/I/W/E/F。 | 40| -t | --type | <type> | 指定类型的日志,示例:-t app core init。 | 41| -D | --domain | <domain> | 指定domain。 | 42| -T | --tag | <tag> | 指定tag。 | 43| -a | --head | <n> | 只显示前<n>行日志。 | 44| -z | --tail | <n> | 只显示后<n>行日志。 | 45| -P | --pid | <pid> | 标识不同的pid。 | 46| -e | --regex | <expr> | 只打印日志消息与<expr>匹配的行,其中<expr>是一个正则表达式。 | 47| -f | --filename | <filename> | 设置落盘的文件名。 | 48| -l | --length | <length> | 设置落盘的文件大小,需要大于等于64K。 | 49| -n | --number | <number> | 设置落盘文件的个数。 | 50| -j | --jobid | <jobid> | 设置落盘任务的ID。 | 51| -w | --write | <control> | 落盘任务控制。 | 52| | | query | 落盘任务查询。 | 53| | | start | 落盘任务开始,命令行参数为文件名、单文件大小、落盘算法、rotate文件数目。 | 54| | | stop | 落盘任务停止。 | 55| | | refresh | 刷新缓冲区的日志到落盘文件。 | 56| | | clear | 删除已经落盘的日志文件。 | 57| -m | --stream | <algorithm> | 落盘方式控制。 | 58| | | none | 无压缩方式落盘。 | 59| | | zlib | zlib压缩算法落盘,落盘文件为.gz。 | 60| | | zstd | zstd压缩算法落盘,落盘文件为.zst。 | 61| -v | --format | <format> | | 62| | | time | 显示本地时间。 | 63| | | color | 显示不同级别显示不同颜色,参数缺省级别颜色模式处理(按黑白方式)。 | 64| | | epoch | 显示相对1970时间。 | 65| | | monotonic | 显示相对启动时间。 | 66| | | usec | 显示微秒精度时间。 | 67| | | nsec | 显示纳秒精度时间。 | 68| | | year | 显示将年份添加到显示的时间。 | 69| | | zone | 显示将本地时区添加到显示的时间。 | 70| -b | --baselevel | <loglevel> | 设置可打印日志的最低等级:D(DEBUG)/I(INFO)/W(WARN)/E(ERROR)/F(FATAL)。 | 71 72 73### 查询相关命令 74 75| 短选项 | 长选项 | 说明 | 76| -------- | -------- | -------- | 77| -h | --help | 打印hilog的命令帮助信息。 | 78 79 80### 时间相关命令 81 82| 短选项 | 长选项 | 参数 | 说明 | 83| -------- | -------- | -------- | -------- | 84| -v | --format | <format> | 时间显示格式。 | 85 86**参数:** 87 88| 参数名 | 说明 | 89| -------- | -------- | 90| time | 显示本地时间。 | 91| color | 显示不同级别显示不同颜色,参数缺省级别颜色模式处理(按黑白方式)。 | 92| epoch | 显示相对1970时间。 | 93| monotonic | 显示相对启动时间。 | 94| usec | 显示微秒精度时间。 | 95| nsec | 显示纳秒精度时间。 | 96| year | 显示将年份添加到显示的时间。 | 97| zone | 显示将本地时区添加到显示的时间。 | 98 99## 常用命令 100 101### 查看帮助命令。 102 103 ``` 104 hilog -h 105 ``` 106 107 **使用样例:** 108 109 ``` 110 $ hilog -h 111 Usage: 112 -h --help 113 Show all help information. 114 Show single help information with option: 115 query/clear/buffer/stats/persist/private/kmsg/flowcontrol/baselevel/domain/combo 116 Querying logs options: 117 No option performs a blocking read and keeps printing. 118 -x --exit 119 Performs a non-blocking read and exits when all logs in buffer are printed. 120 -a <n>, --head=<n> 121 Show n lines logs on head of buffer. 122 -z <n>, --tail=<n> 123 Show n lines logs on tail of buffer. 124 ``` 125 126### 查看日志缓冲区大小。 127 128 ``` 129 hilog -g 130 ``` 131 132 **使用样例:** 133 134 ``` 135 $ hilog -g 136 Log type app buffer size is 16.0M 137 Log type init buffer size is 16.0M 138 Log type core buffer size is 16.0M 139 Log type only_prerelease buffer size is 16.0M 140 ``` 141 142### 修改日志缓冲区大小。 143 144 ``` 145 hilog -G size 146 ``` 147 148 **使用样例:** 149 ``` 150 $ hilog -G 16M 151 Set log type app buffer size to 16.0M successfully 152 Set log type init buffer size to 16.0M successfully 153 Set log type core buffer size to 16.0M successfully 154 Set log type only_prerelease buffer size to 16.0M successfully 155 ``` 156 157### 进程流控开关。 158 159 ``` 160 hilog -Q pidon/pidoff 161 ``` 162 163 164 **使用样例:** 165 166 ``` 167 $ hilog -Q pidon 168 Set flow control by process to enabled successfully 169 $ 170 $ hilog -Q pidoff 171 Set flow control by process to disabled successfully 172 ``` 173 174### domain流控开关。 175 176 ``` 177 hilog -Q domainon/domainoff 178 ``` 179 180 181 **使用样例:** 182 183 ``` 184 $ hilog -Q domainon 185 Set flow control by domain to enabled successfully 186 $ 187 $ hilog -Q domainoff 188 Set flow control by domain to disabled successfully 189 ``` 190 191### 查看指定级别日志。 192 193 ``` 194 hilog -L D/I/W/E/F 195 ``` 196 197 198 **使用样例:** 199 200 ``` 201 $ hilog -L E 202 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 203 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 204 08-28 09:01:56.082 8560 8560 E A00500/com.ohos.settingsdata/SettingsData: decoder failure: /data/migrate/settings_global.xml , error code:-1 205 08-28 09:01:56.082 8560 8560 E A00500/com.ohos.settingsdata/SettingsData: clearXml failed:No such file or directory, error code:13900002 206 08-28 09:01:56.083 8560 8560 E A00500/com.ohos.settingsdata/SettingsData: readText failed:No such file or directory, error code:13900002 207 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 208 08-28 09:01:56.408 8586 8586 E A00500/com.ohos.settingsdata/SettingsData: decoder failure: /data/migrate/settings_global.xml , error code:-1 209 ``` 210 211### 查看指定TAG日志。 212 213 ``` 214 hilog -T tag 215 ``` 216 217 218 **使用样例:** 219 220 ``` 221 $ hilog -T SAMGR 222 08-28 09:27:59.581 610 11504 I C01800/samgr/SAMGR: CommonEventCollect save extraData 1661 223 08-28 09:27:59.581 610 11504 I C01800/samgr/SAMGR: OnReceiveEvent get action: usual.event.BATTERY_CHANGED code: 0, extraDataId 1661 224 08-28 09:27:59.582 610 11504 I C01800/samgr/SAMGR: DoEvent:4 name:usual.event.BATTERY_CHANGED value:0 225 08-28 09:27:59.582 610 11504 W C01800/samgr/SAMGR: LoadSa SA:10120 AddDeath fail,cnt:1,callpid:610 226 08-28 09:27:59.583 610 11504 I C01800/samgr/SAMGR: LoadSa SA:10120 size:1,count:1 227 08-28 09:27:59.601 610 11504 I C01800/samgr/SAMGR: Scheduler SA:10120 loading 228 08-28 09:27:59.965 11518 11518 I C01800/media_analysis_service/SAMGR: SA:10120 OpenSo spend 315ms 229 08-28 09:27:59.965 610 4064 I C01800/samgr/SAMGR: AddProc:media_analysis_service. size:75 230 ``` 231 232### 查看指定进程日志。 233 234 ``` 235 hilog -P pid 236 ``` 237 238 239 **使用样例:** 240 241 ``` 242 $ hilog -P 618 243 08-28 10:19:16.872 618 17729 I C02D15/hiview/XPower: [task_52]#current system load is: 0.028767 244 08-28 10:19:23.997 618 17580 I C02D10/hiview/CpuCollector: CalculateProcessCpuStatInfos: startTime=1724811553746, endTime=1724811563996, startBootTime=47001084, endBootTime=47011335, period=10251 245 08-28 10:19:23.999 618 17580 I C02D10/hiview/CpuCollector: CollectProcessCpuStatInfos: collect process cpu statistics information size=234, isNeedUpdate=1 246 08-28 10:19:24.002 618 17580 W C01650/hiview/Rdb: DB : 247 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 248 08-28 10:19:24.002 618 17580 W C01650/hiview/Rdb: smtime: Wed Aug 28 00:34:30 2024 249 08-28 10:19:24.002 618 17580 W C01650/hiview/Rdb: sctime: Wed Aug 28 00:34:30 2024 250 ``` 251 252### 查看、设置落盘任务。 253 254 ``` 255 hilog -w control 256 ``` 257 > **说明:** 258 > 259 > 查询当前任务: hilog -w query 260 > 261 > 开启hilog落盘任务,并且设置落盘文件数量为1000个: hilog -w start -n 1000 262 > 263 > 开启kmsglog落盘任务,并且设置落盘文件数量为100个: hilog -w start -n 100 -t kmsg 264 > 265 > 停止当前落盘任务: hilog -w stop 266 267 **使用样例:** 268 269 ``` 270 $ hilog -w query 271 Persist task query failed 272 No running persistent task [CODE: -63] 273 $ 274 $ hilog -w start -n 1000 275 Persist task [jobid:1][fileNum:1000][fileSize:4194304] start successfully 276 $ 277 $ hilog -w start -n 100 -t kmsg 278 Persist task [jobid:2][fileNum:100][fileSize:4194304] start successfully 279 $ 280 $ hilog -w stop 281 Persist task [jobid:1] stop successfully 282 Persist task [jobid:2] stop successfully 283 ``` 284 285### 设置可打印日志的最低等级 286 287 ``` 288 hilog -b D/I/W/E/F 289 ``` 290 291 **使用样例:** 292 293 ``` 294 $ hilog -b E 295 Set global log level to E successfully 296 ``` 297<!--Del--> 298### 隐私开关。 299 300 ``` 301 hilog -p on/off 302 ``` 303 304 305 **使用样例:** 306 307 ``` 308 # hilog -p on 309 Set hilog privacy format on successfully 310 # 311 # hilog -p off 312 Set hilog privacy format off successfully 313 ``` 314<!--DelEnd-->