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. 在日志显示中可以筛选日志的打印信息
相关推荐
爱笑的眼睛111 小时前
深入浅出 ArkTS:HarmonyOS 应用开发的语言基石
华为·harmonyos
安卓开发者1 小时前
鸿蒙Next中使用Socket进行网络通信:完整指南与实战
华为·harmonyos
A懿轩A1 小时前
【HarmonyOS应用】《账理通》更新啦!
华为·harmonyos
安卓开发者2 小时前
鸿蒙NEXT Remote Communication Kit:打破设备壁垒,构筑无缝协同体验
华为·harmonyos
爱笑的眼睛112 小时前
HarmonyOS ArkTS深度解析:从语法特性到UI开发实践
华为·harmonyos
无风听海15 小时前
HarmonyOS之LocalStorage
华为·harmonyos
御承扬15 小时前
鸿蒙NEXT系列之鸿蒙PC真机部署应用
华为·harmonyos·鸿蒙pc
little_xianzhong15 小时前
鸿蒙应用主题模式切换实现详解
华为·harmonyos
御承扬17 小时前
鸿蒙NEXT系列之探索鸿蒙PC
华为·harmonyos
2501_9197490317 小时前
鸿蒙:设置浮层(OverlayManager)
华为·harmonyos