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. 在日志显示中可以筛选日志的打印信息
相关推荐
东林知识库26 分钟前
鸿蒙5:HarmonyOS应用开发-线程模型
华为·harmonyos
猫林老师28 分钟前
Flutter for HarmonyOS开发指南(九):测试、调试与质量保障体系
flutter·wpf·harmonyos
Keya1 小时前
鸿蒙Next系统手机使用Charles配置证书并抓包教程
前端·harmonyos
爱笑的眼睛111 小时前
HarmonyOS DataShare数据共享机制深度解析:构建分布式应用的数据桥梁
华为·harmonyos
猫林老师1 小时前
Flutter for HarmonyOS开发指南(五):性能调优与性能分析全攻略
flutter·华为·harmonyos
BlackWolfSky1 小时前
鸿蒙文件操作
macos·华为·harmonyos·鸿蒙
爱笑的眼睛111 小时前
深入理解HarmonyOS Calendar组件:高级日期选择实现与优化
华为·harmonyos
╰つ栺尖篴夢ゞ1 小时前
HarmonyOS之深入解析如何实现语音朗读能力
华为·api·harmonyos next·语音朗读
HMS Core1 小时前
【FAQ】HarmonyOS SDK 闭源开放能力 — Network Kit
华为·harmonyos
爱笑的眼睛111 小时前
HarmonyOS OCR文字识别应用开发:深度指南与分布式实践
华为·harmonyos