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. 在日志显示中可以筛选日志的打印信息
相关推荐
张帅涛_6662 小时前
HarmonyOS ArkUI 构建布局
华为·harmonyos
可惜已不在5 小时前
华为 HCIP-Datacom H12-821 题库 (25)
网络·华为
冯志浩12 小时前
Harmony NEXT:如何给数据库添加自定义分词
harmonyos·掘金·金石计划
爱桥代码的程序媛14 小时前
鸿蒙OpenHarmony【轻量系统芯片移植案例】标准系统方案之瑞芯微RK3568移植案例
嵌入式硬件·harmonyos·鸿蒙·鸿蒙系统·移植·openharmony·鸿蒙开发
AORO_BEIDOU14 小时前
防爆手机+鸿蒙系统,遨游通讯筑牢工业安全基石
5g·安全·智能手机·信息与通信·harmonyos
逢生博客1 天前
Mac 搭建仓颉语言开发环境(Cangjie SDK)
macos·华为·鸿蒙
青柠_项目管理1 天前
PMP证书持有者,在华为、腾讯一般能拿多少薪资?
华为·pmp
小强在此1 天前
【基于开源鸿蒙(OpenHarmony)的智慧农业综合应用系统】
华为·开源·团队开发·智慧农业·harmonyos·开源鸿蒙
Reuuse1 天前
【HCIA-Datacom】华为VRP系统
服务器·网络·华为