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

序言

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

自带Log打印用法

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


//使用
 HiLog.error(TAGLABLE, "当前应用进程:" + this.getProcessInfo().getProcessName());

简单封装

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));
        }
    }
}

你可能感兴趣的:(Harmony开发,Harmony,android)