HarmonyOS开发 - hilog日志系统

文章目录

一、介绍

  1. harmony OS提供了系统日志打印 hilog
  2. 开发者可以通过使用这些接口实现日志相关功能,输出日志时可以指定日志类型、所属业务领域、日志TAG标识、日志级别等。
  3. 系统文档HiLog日志打印

二、对日志的封装

  1. 代码

    import hilog from '@ohos.hilog';

    class LoggerModel {
    public isShowLog = false
    private domain: number
    private prefix: string
    private format: string = '%{public}s,%{public}s'

    constructor(prefix: string) {
    this.prefix = prefix
    this.domain = 0xFF00
    }

    debug(...args: string[]) {
    if (this.isShowLog == true) {
    hilog.debug(this.domain, this.prefix, this.format, args)
    }
    }

    info(...args: string[]) {
    if (this.isShowLog == true) {
    hilog.info(this.domain, this.prefix, this.format, args)
    }
    }

    warn(...args: string[]) {
    if (this.isShowLog == true) {
    hilog.warn(this.domain, this.prefix, this.format, args)
    }

    }

    error(...args: string[]) {
    if (this.isShowLog == true) {
    hilog.error(this.domain, this.prefix, this.format, args)
    }
    }
    }

    export let Logger = new LoggerModel('[DK_LOG]')

#2. 调用方法

复制代码
Logger.info("version");
  1. 在日志显示中可以筛选日志的打印信息
相关推荐
__Benco2 小时前
OpenHarmony - 小型系统内核(LiteOS-A)(十),魔法键使用方法,用户态异常信息说明
人工智能·harmonyos
NapleC16 小时前
HarmonyOS:一多能力介绍:一次开发,多端部署
华为·harmonyos
我爱学习_zwj18 小时前
【鸿蒙HarmonyOS】深入理解router与Navigation
华为·harmonyos
NapleC18 小时前
HarmonyOS:1.7
harmonyos
鸿蒙布道师18 小时前
鸿蒙NEXT开发通知工具类(ArkTs)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei
鸿蒙布道师19 小时前
鸿蒙NEXT开发网络相关工具类(ArkTs)
android·ios·华为·harmonyos·arkts·鸿蒙系统·huawei
半梅芒果干19 小时前
HarmonyOs @hadss/hmrouter路由接入
华为·harmonyos
心走20 小时前
鸿蒙WebRTC编译指南&踩坑(Native 编译指导)
harmonyos·音视频开发
冯志浩1 天前
HarmonyOS - 嵌套类属性状态管理装饰器:ObservedV2 和 Trace
harmonyos·掘金·金石计划