赞
踩
static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x00201, "MY_TAG");
接口名 | 功能描述 |
---|---|
debug(HiLogLabel label, String format, Object… args) | 输出DEBUG级别的日志。DEBUG级别日志表示仅用于应用调试,默认不输出,输出前需要在设备的“开发人员选项”中打开“USB调试”开关 |
info(HiLogLabel label, String format, Object… args) | 输出INFO级别的日志。INFO级别日志表示普通的信息 |
warn(HiLogLabel label, String format, Object… args) | 输出WARN级别的日志。WARN级别日志表示存在警告 |
error(HiLogLabel label, String format, Object… args) | 输出ERROR级别的日志。ERROR级别日志表示存在错误 |
fatal(HiLogLabel label, String format, Object… args) | 输出FATAL级别的日志。FATAL级别日志表示出现致命错误、不可恢复错误 |
HiLog.warn(LABEL, "Failed to visit %{private}s, reason:%{public}d.", url, errno);
06-23 16:08:36.908 23597-23597/com.example.myapplication W 00201/MY_TAG: Failed to visit <private>, reason:503.
package com.example.myapplication.slice; // 请开发者根据实际情况写包名 import ohos.aafwk.ability.AbilitySlice; import ohos.aafwk.content.Intent; import ohos.agp.components.Button; import ohos.agp.components.DirectionalLayout; import ohos.hiviewdfx.HiLog; import ohos.hiviewdfx.HiLogLabel; public class MainAbilitySlice extends AbilitySlice { // 定义日志标签 private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, 0x00201, "MY_TAG"); @Override public void onStart(Intent intent) { super.onStart(intent); // 添加一个按钮 DirectionalLayout directionalLayout = new DirectionalLayout(getContext()); Button button = new Button(getContext()); button.setText("Click!"); button.setTextSize(200); if (button != null) { // 为按钮设置点击回调 button.setClickedListener(component -> { // 打印一条日志 HiLog.info(LABEL, "Hey! You have successfully printed a log."); }); } directionalLayout.addComponent(button); super.setUIContent(directionalLayout); } @Override public void onActive() { super.onActive(); } @Override public void onForeground(Intent intent) { super.onForeground(intent); } }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。