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. 在日志显示中可以筛选日志的打印信息
相关推荐
o***Y3632 小时前
鸿蒙NEXT(五):鸿蒙版React Native架构浅析
react native·架构·harmonyos
lqj_本人2 小时前
混合应用落地:用 OpenHarmony + Cordova 封装 Web 2048 游戏
harmonyos
D***t1313 小时前
HarmonyOS在智能家居中的华为生态
华为·智能家居·harmonyos
b***74883 小时前
HarmonyOS在智能家居中的语音助手
华为·智能家居·harmonyos
u***j3243 小时前
HarmonyOS分布式能力核心技术深度解析
分布式·华为·harmonyos
7***n754 小时前
HarmonyOS分布式数据管理
分布式·华为·harmonyos
S***y3964 小时前
HarmonyOS在智能家居中的情景模式
华为·智能家居·harmonyos
IT充电站4 小时前
HarmonyOS 帧动画 animator
harmonyos
IT充电站4 小时前
HarmonyOS 位置服务全攻略:精准定位、地理编码与后台持续定位实现
harmonyos
IT充电站4 小时前
HarmonyOS 组件导航(Navigation)
harmonyos