当前位置:   article > 正文

【Harmony】日志打印工具(直接粘贴复用)_harmonyos 打印日志

harmonyos 打印日志

序言

Harmony开发中,其中自带的日志打印使用起来感觉真的是一言难尽,感觉挺麻烦的。

自带Log打印用法

  public static final HiLogLabel TAGLABLE = new HiLogLabel(HiLog.LOG_APP, 0x00201, "MainAbilitySlice");


//使用
 HiLog.error(TAGLABLE, "当前应用进程:" + this.getProcessInfo().getProcessName());
  • 1
  • 2
  • 3
  • 4
  • 5
简单封装
public class LogUtil {
    private static final int DOMAIN = 0x10086;
    private static final String TAG = "LogUtil";
    private static final HiLogLabel LABEL = new HiLogLabel(HiLog.LOG_APP, DOMAIN, TAG);

    public static void debug(String message) {
        HiLog.debug(LABEL, message);
    }

    public static void info(String message) {
        HiLog.info(LABEL, message);
    }

    public static void error(String message) {
        HiLog.error(LABEL, message);
    }

    public static void LongLog(String msg) {
        int maxLogLength = 1000;
        for (int i = 0; i <= msg.length() / maxLogLength; i++) {
            int start = i * maxLogLength;
            int end = (i + 1) * maxLogLength;
            end = Math.min(end, msg.length());
            error(msg.substring(start, end));
        }
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/281544
推荐阅读
相关标签
  

闽ICP备14008679号