为了让刚入门的鸿蒙开发者迅速掌握hilog工具的使用方法,特编写了该篇命令行使用手册供开发者查阅,让开发者在自己的的开发和调试的过程中充分认识hilog工具的优势和便捷。
一、查询日志
1、指定模块查询
-t 用于指定输出日志的类型/模块,目前系统共包含app/core/kmsg/init四种日志类型。
hilog -t app|core|kmsg|init 阻塞式实时查询模块日志,-t可以与其他参数一起使用。
hilog -t app|core|kmsg|init -x 非阻塞式实时查询模块日志,-x选项也可以和hilog的其他选项同时使用。
示例如下:
# hilog -t kmsg
01-01 00:00:03.909 0 0 I fffff/kmsg: Booting Linux on physical CPU 0x0
01-01 00:00:03.909 0 0 W fffff/kmsg: Linux version 5.10.79 (osm@ubuntu) (OHOS () clang version 10.0.1.480513 (llvm-project b2cadc87d64786377748bdb6bc5e6949492f01ab), GNU ld (Linaro_Binutils-2019.12) 2.28.2.20170706) #1 SMP Wed Apr 6 09:37:37 CST 2022
01-01 00:00:03.909 0 0 I fffff/[410fc075]: CPU: ARMv7 Processor revision 5 (ARMv7), cr=10c5387d
01-01 00:00:03.909 0 0 I fffff/kmsg: CPU: div instructions available: patching division code
01-01 00:00:03.909 0 0 I fffff/kmsg: CPU: PIPT / VIPT nonaliasing data cache, VIPT aliasing instruction cache
01-01 00:00:03.909 0 0 I fffff/kmsg: OF: fdt: Machine model: Hisilicon HI3516DV300 DEMO Board
01-01 00:00:03.909 0 0 I fffff/kmsg: Memory policy: Data cache writealloc
01-01 00:00:03.909 0 0 D fffff/kmsg: cma: dma_contiguous_reserve(limit ffffffff)
01-01 00:00:03.909 0 0 D fffff/kmsg: cma: dma_contiguous_reserve: reserving 64 MiB for global area
2、指定tag查询
-T选项为指定tag。标签:用于指定日志标识,可以为任意字符串,建议标识调用所在的类或者业务行为。
hilog -t app|core|kmsg|init -T <tag> 模块内指定tag, -T可以与其他参数一起使用。
hilog -T <tag> 只指定tag。
示例如下:
# hilog -t core -T BatteryThread
01-02 02:10:03.771 725 820 I 02500/BatteryThread: UpdateBatteryInfo: BatteryInfo capacity=11, voltage=4123456, temperature=222, healthState=1, pluggedType=2, pluggedMaxCurrent=-1, pluggedMaxVoltage=-1, chargeState=3, chargeCounter=4000000, present=0, technology=Li-ion
01-02 02:10:03.771 725 820 I 02500/BatteryThread: UpdateBatteryInfo g_callback is nullptr
01-02 02:10:03.771 725 820 I 02500/BatteryThread: LoopingThreadEntry: timeout=-1, nevents=1
01-02 02:10:13.772 725 820 I 02500/BatteryThread: UpdateBatteryInfo: BatteryInfo capacity=11, voltage=4123456, temperature=222, healthState=1, pluggedType=2, pluggedMaxCurrent=-1, pluggedMaxVoltage=-1, chargeState=3, chargeCounter=4000000, present=0, technology=Li-ion
01-02 02:10:13.772 725 820 I 02500/BatteryThread: UpdateBatteryInfo g_callback is nullptr
01-02 02:10:13.772 725 820 I 02500/BatteryThread: LoopingThreadEntry: timeout=-1, nevents=1
01-02 02:10:23.772 725 820 I 02500/BatteryThread: UpdateBatteryInfo: BatteryInfo capacity=11, voltage=4123456,
# hilog -T BatteryThread
01-02 02:14:03.771 725 820 I 02500/BatteryThread: UpdateBatteryInfo: BatteryInfo capacity=11, voltage=4123456, temperature=222, healthState=1, pluggedType=2, pluggedMaxCurrent=-1, pluggedMaxVoltage=-1, chargeState=3, chargeCounter=4000000, present=0, technology=Li-ion
01-02 02:14:03.771 725 820 I 02500/BatteryThread: UpdateBatteryInfo g_callback is nullptr
01-02 02:14:03.771 725 820 I 02500/BatteryThread: LoopingThreadEntry: timeout=-1, nevents=1
01-02 02:14:13.772 725 820 I 02500/BatteryThread: UpdateBatteryInfo: BatteryInfo capacity=11, voltage=4123456, temperature=222, healthState=1, pluggedType=2, pluggedMaxCurrent=-1, pluggedMaxVoltage=-1, chargeState=3, chargeCounter=4000000, present=0, technology=Li-ion
3、指定level查询
-L 指定日志级别,HiLog中定义了DEBUG、INFO、WARN、ERROR、FATAL五种日志级别。
hilog -t app|core|kmsg|init -L D|I|W|E|F 模块内指定level查询,D:debug, I:info, W:warning, E:error, F:fatal。
hilog -L D|I|W|E|F 只指定level查询,可以与其他参数一起使用。
示例如下:
# hilog -t app -L I
01-01 08:15:00.030 875 875 I 02200/JsApp: SystemUI_Default tag: TimeManager --> notifyTimeChange
01-01 08:15:00.031 875 875 I 02200/JsApp: SystemUI_Default tag: EventManager --> publish localEvent type: Time_Change_Event
01-01 08:16:00.031 875 875 I 02200/JsApp: SystemUI_Default tag: CommonEvent_TimeManager --> handle common event: usual.event.TIME_TICK
01-01 08:16:00.031 875 875 I 02200/JsApp: SystemUI_Default tag: TimeManager --> notifyTimeChange
01-01 08:16:00.032 875 875 I 02200/JsApp: SystemUI_Default tag: EventManager --> publish localEvent type: Time_Change_Event
01-01 08:17:00.030 875 875 I 02200/JsApp: SystemUI_Default tag: CommonEvent_TimeManager --> handle common event: usual.event.TIME_TICK
# hilog -L I
01-01 08:15:00.030 875 875 I 02200/JsApp: SystemUI_Default tag: TimeManager --> notifyTimeChange
01-01 08:15:00.031 875 875 I 02200/JsApp: SystemUI_Default tag: EventManager --> publish localEvent type: Time_Change_Event
01-01 08:16:00.031 875 875 I 02200/JsApp: SystemUI_Default tag: CommonEvent_TimeManager --> handle common event: usual.event.TIME_TICK
01-01 08:16:00.031 875 875 I 02200/JsApp: SystemUI_Default tag: TimeManager --> notifyTimeChange
01-01 08:16:00.032 875 875 I 02200/JsApp: SystemUI_Default tag: EventManager --> publish localEvent type: Time_Change_Event
01-01 08:17:00.030 875 875 I 02200/JsApp: SystemUI_Default tag: CommonEvent_TimeManager --> handle common event: usual.event.TIME_TICK
4、指定domain查询
-D选项为指定domain。服务域:日志的服务域,用于指定输出日志所对应的业务领域。这是一个十六进制整数,范围从 0x0 到 0xFFFFF。建议使用0xAAABB格式,其中AAA表示子系统,BB表示模块。
hilog -t app|core|kmsg|init -D <domian> 模块内指定domian查询。
hilog -D <domain> 只指定domian查询,可以与其他参数一起使用。
# hilog -D 0x0 -t core
01-01 04:36:03.140 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:36:05.299 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:36:07.459 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:36:09.619 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:36:11.780 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:36:13.939 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:36:16.099 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:36:18.259 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:36:20.419 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
# hilog -D 0x0
01-01 04:37:01.459 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:37:03.619 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:37:05.779 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:37:07.939 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:37:10.100 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:37:12.260 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:37:14.419 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
01-01 04:37:16.579 91 145 I 00000/AppSpawnServer: AppSpawnServer::ConnectionPeer connectFd is -11
5、排除查询
type、level、domain、tag支持排除查询,排除查询可以使用以”^“开头的参数和分隔符”,”来完成。
hilog [-t ^app|kmsg|init|core] [-T ^<tag>] [-L ^D|I|W|E|F] [-D ^<domain>]。
示例如下:
# hilog -t ^app,kmsg,init -T ^BatteryThread
01-02 02:07:00.071 332 332 E 01400/OHOS::ROSEN: RsDebug RSHardwareProcessor::ProcessSurface surfaceNode id:3758096384048 name:[SystemUi_NavigationBar] dst [0 912 480 48]SrcRect [480 48] rawbuffer [480 48] surfaceBuffer [480 48] buffaddr:0x1249230, z:2.000000, globalZOrder:2, blendType = 3
01-02 02:07:00.071 332 332 D 01400/OHOS::ROSEN: RsDebug RSHardwareProcessor::CropLayers this layer no need to crop
01-02 02:07:00.071 332 332 D 01400/OHOS::ROSEN: RsDebug RSHardwareProcessor::CropLayers this layer no need to crop
01-02 02:07:00.071 332 332 D 01400/OHOS::ROSEN: RsDebug RSHardwareProcessor::CropLayers this layer no need to crop
01-02 02:07:00.071 332 332 D 01400/Composer: Repaint: Repaint: start
01-02 02:07:00.071 332 332 D 01400/DISP: [SetLayerAlpha@hdi_session.cpp:273]
01-02 02:07:00.071 332 332 D 01400/DISP: [CallLayerFunction@hdi_session.h:48] device Id : 0
01-02 02:07:00.071 332 332 D 01400/DISP: [GetHdiLayer@hdi_display.cpp:221] id : 3
二、查询和设置信息
1、查询和设置模块的buffer
(1)查询模块的buffer
显示的日志内容为各模块buffer里当前缓存的内容,并实时更新,超出buffer的内容会覆盖掉旧的内容。
hilog -g -t app|core|kmsg|init 查询日志类型为app/core/kmsg/init的buffer大小:
示例如下:
# hilog -g -t core
core buffer size is 256K
#
(2)设置模块的buffer
hilog -G <size> -t app|core|kmsg|init 设置指定<type>日志类型缓冲区的大小,配合-t指定某一类型使用,默认app和core, 可使用B/K/M/G为单位。
示例如下:
# hilog -t app -g
app buffer size is 256K
# hilog -t app -G 2M
app buffer size is 2M
# hilog -t app -g
app buffer size is 2M
#
(3)清除buffer日志
hilog -t app|core|kmsg|init -r -r选项清除buffer日志,配合-t指定某一类型使用,默认app和core。
# hilog -t app -r
app log clear success
# hilog -t app
#
2、查询和清除统计信息
(1)查询统计信息
hilog -t app|core|kmsg|init -s -s查询统计信息,需配合-t或-D使用。
示例如下:
# hilog -t app -s
app print log length is 1M
app cache log length is 461K
app dropped log lines is 0B
#
(2)清除统计信息
hilog -t app|core|kmsg|init -S -S清除统计信息,需配合-t或-D使用。
# hilog -t app -s
app print log length is 1M
app cache log length is 461K
app dropped log lines is 0B
#
#
# hilog -t app -S
app statistic info clear success
# hilog -t app -s
app print log length is 0B
app cache log length is 0B
app dropped log lines is 0B
#
三、日志落盘
1、使用方法
hilog -w start [-f “xxx”] [-l <length>] [-j <jobid>] [-m <algorithm>] [-n <number>] 启动落盘任务。
hilog -w query [-j <jobid>] 查询落盘任务。
hilog -w stop [-j <jobid>] 停止落盘任务。
示例如下:
# hilog -w query
#
#hilog -w start -f "hilog" -l 66k -j 222 -m zlib -n 2
Persist task [jobid:222] started successfully
#cd /data/log/hilog
#
# ls -al
total 100
drwxr-x--- 2 logd log 4096 1970-01-02 03:34 .
drwxrwx--- 6 system log 4096 1970-01-01 00:38 ..
-rw-r----- 1 logd system 65540 1970-01-02 03:34 .persisterInfo_222
-rw-r----- 1 logd system 132 1970-01-02 03:34 .persisterInfo_222.info
-rw-r----- 1 logd system 12239 1970-01-02 03:34 hilog.002.19700102-033431.gz
-rw-r----- 1 logd system 6883 1970-01-02 03:34 hilog.003.19700102-033431.gz
# hilog -w query -j 222 #指定jobid查询
222 core,app zlib /data/log/hilog/hilog 67584 2
# hilog -w query #查询全部落盘任务
222 core,app zlib /data/log/hilog/hilog 67584 2
# hilog -w stop -j 222
Persist task [jobid:222] stopped successfully
# ls -al
total 36
drwxr-x--- 2 logd log 4096 1970-01-02 03:35 .
drwxrwx--- 6 system log 4096 1970-01-01 00:38 ..
-rw-r----- 1 logd system 12239 1970-01-02 03:34 hilog.002.19700102-033431.gz
-rw-r----- 1 logd system 13000 1970-01-02 03:35 hilog.003.19700102-033431.gz
#
2、案例展示
案例需求:抓取模块最早的log,即:开机启动过程中模块产生的log,并将内容保存到文件导出设备。
第一步:启动落盘任务。
示例如下:
#
# hilog -w start -f "hilog" -l 66k -j 111 -m zlib -n 2 -t kmsg
Persist task [jobid:111] started successfully
#
#cd /data/log/hilog
#
# ls -al
total 116
drwxr-x--- 2 logd log 4096 1970-01-02 19:31 .
drwxrwx--- 6 system log 4096 1970-01-01 00:38 ..
-rw-r----- 1 logd system 65540 1970-01-02 19:31 .persisterInfo_111
-rw-r----- 1 logd system 132 1970-01-02 19:31 .persisterInfo_111.info
-rw-r----- 1 logd system 19245 1970-01-02 19:31 hilog.000.19700102-193128.gz
-rw-r----- 1 logd system 16069 1970-01-02 19:31 hilog.001.19700102-193128.gz
#
第二步:重启设备
# reboot
D:share>
第三步:设备起来后,停止落盘任务。
D:share>hdc_std.exe shell
#
# cd /data/log/hilog/
#
# ls -al
total 108
drwxr-x--- 2 logd log 4096 1970-01-02 19:32 .
drwxrwx--- 6 system log 4096 1970-01-01 00:38 ..
-rw-r----- 1 logd system 65540 1970-01-02 19:32 .persisterInfo_111
-rw-r----- 1 logd system 132 1970-01-02 19:32 .persisterInfo_111.info
-rw-r----- 1 logd system 16192 1970-01-02 19:31 hilog.003.19700102-193147.gz #注意:log文件的命名是随时间实时更新的
-rw-r----- 1 logd system 8500 1970-01-02 19:32 hilog.004.19700102-193213.gz
#
# hilog -w stop
Persist task [jobid:111] stopped successfully
# ls -al
total 36
drwxr-x--- 2 logd log 4096 1970-01-02 19:34 .
drwxrwx--- 6 system log 4096 1970-01-01 00:38 ..
-rw-r----- 1 logd system 16192 1970-01-02 19:31 hilog.003.19700102-193147.gz
-rw-r----- 1 logd system 8500 1970-01-02 19:32 hilog.004.19700102-193213.gz
#
#
第四步:将log文件导出设备,即可得到模块的启动log文件。
#
# exit
D:share>hdc_std.exe file recv /data/log/hilog/hilog.003.19700102-193147.gz D:share
FileTransfer finish, Size:16192 time:55ms rate:294.40kB/s
D:share>hdc_std.exe file recv /data/log/hilog/hilog.004.19700102-193213.gz D:share
FileTransfer finish, Size:8500 time:25ms rate:340.00kB/s
D:share>
D:share>dir
......
2022/05/09 14:04 3,424,768 hdc_std.exe
2022/05/20 10:24 16,192 hilog.003.19700102-193147.gz
2022/05/20 10:25 8,500 hilog.004.19700102-193213.gz
......
D:share>
四、其他辅助命令
-a <n> 只显示前<n>行日志。
-z <n> 只显示后<n>行日志。
示例如下:
# hilog -t app -a 5
01-02 03:12:00.030 875 875 I 02200/JsApp: SystemUI_Default tag: CommonEvent_TimeManager --> handle common event: usual.event.TIME_TICK
01-02 03:12:00.030 875 875 I 02200/JsApp: SystemUI_Default tag: TimeManager --> notifyTimeChange
01-02 03:12:00.030 875 875 I 02200/JsApp: SystemUI_Default tag: EventManager --> publish localEvent type: Time_Change_Event
01-02 03:13:00.031 875 875 I 02200/JsApp: SystemUI_Default tag: CommonEvent_TimeManager --> handle common event: usual.event.TIME_TICK
01-02 03:13:00.031 875 875 I 02200/JsApp: SystemUI_Default tag: TimeManager --> notifyTimeChange
#
#
# hilog -t app -z 5
01-02 04:02:00.032 875 875 I 02200/JsApp: SystemUI_Default tag: EventManager --> publish localEvent type: Time_Change_Event
01-02 04:02:00.032 875 875 I 02200/JsApp: SystemUI_Default tag: TimeManager --> notifyTimeChange
01-02 04:02:00.031 875 875 I 02200/JsApp: SystemUI_Default tag: CommonEvent_TimeManager --> handle common event: usual.event.TIME_TICK
01-02 04:01:00.030 875 875 I 02200/JsApp: SystemUI_Default tag: EventManager --> publish localEvent type: Time_Change_Event
01-02 04:01:00.030 875 875 I 02200/JsApp: SystemUI_Default tag: TimeManager --> notifyTimeChange
#
这里只演示了常用的命令选项,如果需要其他选项请自行查阅附件表格,或通过hilog -h查询。
附:hilog命令行使用表格
短选项 |
长选项 |
参数 |
说明 |
-h |
–help |
帮助命令 |
|
缺省 |
缺省 |
阻塞读日志,不退出 |
|
-x |
–exit |
非阻塞读日志,读完退出 |
|
-g |
查询buffer的大小,配合-t指定某一类型使用,默认app和core |
||
-G |
–buffer-size |
<size> |
设置指定<type>日志类型缓冲区的大小,配合-t指定某一类型使用,默认app和core, 可使用B/K/M/G为单位 |
-r |
清除buffer日志,配合-t指定某一类型使用,默认app和core |
||
-p |
–privacy |
<on/off> |
支持系统调试时日志隐私开关控制 |
on |
打开隐私开关,显示<private> |
||
off |
关闭隐私开关,显示明文 |
||
-k |
<on/off> |
Kernel日志读取开关控制 |
|
on |
打开读取kernel日志 |
||
off |
关闭读取kernel日志 |
||
-s |
–statistics |
查询统计信息,需配合-t或-D使用 |
|
-S |
清除统计信息,需配合-t或-D使用 |
||
-Q |
<control-type> |
流控缺省配额开关控制 |
|
pidon |
进程流控开关打开 |
||
pidoff |
进程流控开关关闭 |
||
domainon |
domain流控开关打开 |
||
domainoff |
domain流控开关关闭 |
||
-L |
–level |
<level> |
指定级别的日志,示例:-L D/I/W/E/F |
-t |
–type |
<type> |
指定类型的日志,示例:-t app core init |
-D |
–domain |
<domain> |
指定domain |
-T |
–Tag |
<tag> |
指定tag |
-a |
–head |
<n> |
只显示前<n>行日志 |
-z |
–tail |
<n> |
只显示后<n>行日志 |
-P |
–pid |
<pid> |
标识不同的pid |
-e |
–regex |
<expr> |
只打印日志消息与<expr>匹配的行,其中<expr>是一个正则表达式 |
-f |
–filename |
<filename> |
设置落盘的文件名 |
-l |
–length |
<length> |
设置落盘的文件大小,需要大于等于64K |
-n |
–number |
<number> |
设置落盘文件的个数 |
-j |
–jobid |
<jobid> |
设置落盘任务的ID |
-w |
–write |
<control> |
落盘任务控制 |
query |
落盘任务查询 |
||
start |
落盘任务开始,命令行参数为文件名、单文件大小、落盘算法、rotate文件数目. |
||
stop |
落盘任务停止 |
||
-m |
–stream |
<algorithm> |
落盘方式控制 |
none |
无压缩方式落盘 |
||
zlib |
zlib压缩算法落盘,落盘文件为.gz |
||
zstd |
zstd压缩算法落盘,落盘文件为.zst |
||
-v |
–format |
<format> |
|
time |
显示本地时间 |
||
color |
显示不同级别显示不同颜色,参数缺省级别颜色模式处理(按黑白方式) |
||
epoch |
显示相对1970时间 |
||
monotonic |
显示相对启动时间 |
||
usec |
显示微秒精度时间 |
||
nsec |
显示纳秒精度时间 |
||
year |
显示将年份添加到显示的时间 |
||
zone |
显示将本地时区添加到显示的时间 |
||
-b |
–baselevel |
<loglevel> |
设置可打印日志的最低等级:D(DEBUG)/I(INFO)/W(WARN)/E(ERROR)/F(FATAL) |
文章版权声明
1 原创文章作者:如此。,如若转载,请注明出处: https://www.52hwl.com/101959.html
2 温馨提示:软件侵权请联系469472785#qq.com(三天内删除相关链接)资源失效请留言反馈
3 下载提示:如遇蓝奏云无法访问,请修改lanzous(把s修改成x)
4 免责声明:本站为个人博客,所有软件信息均来自网络 修改版软件,加群广告提示为修改者自留,非本站信息,注意鉴别