其他分享
首页 > 其他分享> > 鸿蒙OS应用开发之——Log日志打印

鸿蒙OS应用开发之——Log日志打印

作者:互联网

一 概述

二 输出实例

2.1 如何输出日志代码

 HiLogLabel label=new HiLogLabel(HiLog.LOG_APP, 0x00201, "TAG");
 HiLog.error(label,"log日志");

2.2 查看输出结果

状态栏切换到HiLog标签下,选择要查看的设备,选择设备类型(Error),service domain输入00201

三 概念说明

3.1 HiLogLabel

HiLogLabel(int type, int domain, String tag)
参数类型说明
type输出日志类型(见type表)
domain从0x0到0xFFFFF的十六进制整数
tag用于标识方法调用的类或服务行为的字符串常量

type

type
HiLog.LOG_APP0
HiLog.DEBUG3
HiLog.INFO4
HiLog.WARN5
HiLog.ERROR6
HiLog.FATAL7

3.2 HiLog

HiLog.info(HiLogLabel label, String format, Object... args)
方法参数一参数二参数三(可变参数)
debuglabel输出Log内容可空
infolabel输出Log内容可空
warnlabel输出Log内容可空
errorlabel输出Log内容可空
fatallabel输出Log内容可空

四 高级应用(private和public修饰符)

4.1 说明

4.2 代码

 String url="localhost";
 int errno=500;
 HiLogLabel label=new HiLogLabel(HiLog.LOG_APP, 0x00201, LogUtils.class.getSimpleName());
 HiLog.warn(label, "Failed to visit %{private}s, reason:%{public}d.", url, errno);

4.3 显示结果(url没有显示)

12-28 17:34:59.359 25702-25702/? W 00201/LogUtils: Failed to visit <private>, reason:500.

标签:输出,Log,鸿蒙,HiLogLabel,HiLog,可空,日志,OS
来源: https://blog.csdn.net/Calvin_zhou/article/details/111879593