Understanding what is happening on your target device during development is critical.

The OpenHarmony Device Connector tool (HDC) is a command-line tool for connecting to your device for tasks such as publishing apps, sending & receiving files from a device, accessing a shell for the device and accessing logs.
Whilst DevEcoStudio does provide access to device logging, it is sometimes helpful to monitor logs separately, or watch for the log output for different processes.
Here are some tips for using HDC to access logs an application’s logs.
Connecting to your device
The HDC tools is part of the HarmonyOS/OpenHarmony SDK. With a device that has developer options enabled (including USB debugging), you can get the device’s ID and open a shell session as follows:
.\hdc.exe list targets
[lists the available devices]
.\hdc.exe -t 890122445634304442016c0e0a2eba33 shell
Hilog Commands
Once connected to your device with with a shell session, you can see the available options for using the Hilog logging service.
hilog -h
Usage:
-h --help
Show all help information.
Show single help information with option:
query/clear/buffer/stats/persist/private/kmsg/flowcontrol/baselevel/domain/combo
Querying logs options:
No option performs a blocking read and keeps printing.
-x --exit
Performs a non-blocking read and exits when all logs in buffer are printed.
-a <n>, --head=<n>
Show n lines logs on head of buffer.
-z <n>, --tail=<n>
Show n lines logs on tail of buffer.
-t <type>, --type=<type>
Show specific type/types logs with format: type1,type2,type3
Don't show specific type/types logs with format: ^type1,type2,type3
Type coule be: app/core/init/kmsg, kmsg can't combine with others.
Default types are: app,core,init.
-L <level>, --level=<level>
Show specific level/levels logs with format: level1,level2,level3
Don't show specific level/levels logs with format: ^level1,level2,level3
Long and short level string are both accepted
Long level string coule be: DEBUG/INFO/WARN/ERROR/FATAL.
Short level string coule be: D/I/W/E/F.
Default levels are all levels.
-D <domain>, --domain=<domain>
Show specific domain/domains logs with format: domain1,domain2,doman3
Don't show specific domain/domains logs with format: ^domain1,domain2,doman3
Max domain count is 5.
See domain description at the end of this message.
-T <tag>, --tag=<tag>
Show specific tag/tags logs with format: tag1,tag2,tag3
Don't show specific tag/tags logs with format: ^tag1,tag2,tag3
Max tag count is 10.
-P <pid>, --pid=<pid>
Show specific pid/pids logs with format: pid1,pid2,pid3
Don't show specific domain/domains logs with format: ^pid1,pid2,pid3
Max pid count is 5.
-e <expr>, --regex=<expr>
Show the logs which match the regular expression <expr>.
-v <format>, --format=<format>
Show logs in different formats, options are:
color or colour display colorful logs by log level.i.e.
DEBUG INFO WARN ERROR FATAL
time format options are(single accepted):
time display local time, this is default.
epoch display the time from 1970/1/1.
monotonic display the cpu time from bootup.
time accuracy format options are(single accepted):
msec display time by millisecond, this is default.
usec display time by microsecond.
nsec display time by nanosecond.
year display the year when -v time is specified.
zone display the time zone when -v time is specified.
Different types of formats can be combined, such as:
-v color -v time -v msec -v year -v zone.
-r
Remove all logs in hilogd buffer, advanced option:
-t <type>, --type=<type>
Remove specific type/types logs in buffer with format: type1,type2,type3
Type coule be: app/core/init/kmsg.
Default types are: app,core
-g
Query hilogd buffer size, advanced option:
-t <type>, --type=<type>
Query specific type/types buffer size with format: type1,type2,type3
Type coule be: app/core/init/kmsg.
Default types are: app,core
-G <size>, --buffer-size=<size>
Set hilogd buffer size, <size> could be number or number with unit.
Unit could be: B/K/M/G which represents Byte/Kilobyte/Megabyte/Gigabyte.
<size> range: [64.0K,64.0K].
Advanced option:
-t <type>, --type=<type>
Set specific type/types log buffer size with format: type1,type2,type3
Type coule be: app/core/init/kmsg.
Default types are: app,core
**It's a persistant configuration**
-s, --statistics
Query log statistic information.
Set param persist.sys.hilog.stats true to enable statistic.
Set param persist.sys.hilog.stats.tag true to enable statistic of log tag.
-S
Clear hilogd statistic information.
-w <control>,--write=<control>
Log persistance task control, options are:
query query tasks informations
stop stop all tasks
start start one task
Persistance task is used for saving logs in files.
The files are saved in directory: /data/log/hilog/
Advanced options:
-f <filename>, --filename=<filename>
Set log file name, name should be valid of Linux FS.
-l <length>, --length=<length>
Set single log file size. <length> could be number or number with unit.
Unit could be: B/K/M/G which represents Byte/Kilobyte/Megabyte/Gigabyte.
<length> range: [64.0K, 512.0M].
-n <number>, --number<number>
Set max log file numbers, log file rotate when files count over this number.
<number> range: [2, 1000].
-m <compress algorithm>,--stream=<compress algorithm>
Set log file compressed algorithm, options are:
none write file with non-compressed logs.
zlib write file with zlib compressed logs.
-j <jobid>, --jobid<jobid>
Start/stop specific task of <jobid>.
<jobid> range: [10, 0xffffffff).
User can start task with options (t/L/D/T/P/e/v) as if using them when "Query logs" too.
**It's a persistant configuration**
-p <on/off>, --privacy <on/off>
Set HILOG api privacy formatter feature on or off.
**It's a temporary configuration, will be lost after reboot**
-k <on/off>, --kmsg <on/off>
Set hilogd storing kmsg log feature on or off
**It's a persistant configuration**
-Q <control-type>
Set log flow-control feature on or off, options are:
pidon process flow control on
pidoff process flow control off
domainon domain flow control on
domainoff domain flow control off
**It's a temporary configuration, will be lost after reboot**
-b <loglevel>, --baselevel=<loglevel>
Set global loggable level to <loglevel>
Long and short level string are both accepted.
Long level string coule be: DEBUG/INFO/WARN/ERROR/FATAL/X.
Short level string coule be: D/I/W/E/F/X.
X means that loggable level is higher than the max level, no log could be printed.
Advanced options:
-D <domain>, --domain=<domain>
Set specific domain loggable level.
See domain description at the end of this message.
-T <tag>, --tag=<tag>
Set specific tag loggable level.
The priority is: tag level > domain level > global level.
**It's a temporary configuration, will be lost after reboot**
The first layer options can't be used in combination, ILLEGAL expamples:
hilog -S -s; hilog -w start -r; hilog -p on -k on -b D
Domain description:
Log type "core" & "init" are used for OS subsystems, the range is [0xd000000, 0xd0fffff]
Log type "app" is used for applications, the range is [0x0, 0xffff]
To reduce redundant info when printing logs, only last five hex numbers of domain are printed
So if user wants to use -D option to filter OS logs, user should add 0xD0 as prefix to the printed domain:
Exapmle: hilog -D 0xD0xxxxx
The xxxxx is the domain string printed in logs.
Useful logging options
# Show logs with different colours based on log level
hilog -v color
# Show logs written with a given tag
hilog -T my_tag
# Show logs with one of these log levels: DEBUG/INFO/WARN/ERROR/FATAL
hilog -L DEBUG
# Show logs that have the text 'snappmobile' in them using regex
hilog -e .*\b(snappmobile)\b.*
# Show logs from an app based on the logging Domain '0xfffe'
hilog -D 0xfffe
# Clear the log cache
hilog -r
The effect is to create a ‘tail’ of the logging output with the specified options applied.
Options can also be combine, for example.
#Show logs in colour for the tag 'datasource' and the Domain 0xfffe.
hilog -v color -T datasource -D 0xfffe
#Show logs in colour for the tag 'datasource' that are warnings
hilog -v color -T datasource -L WARN
#Show logs in colour for the tag 'network' that have the text 'retry'
hilog -v color -T network -e .*\b(retry)\b.*