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. 在日志显示中可以筛选日志的打印信息
相关推荐
马剑威(威哥爱编程)1 小时前
【共创稿事节】HarmonyOS 7 文搜图实战:自然语言检索本地图片,全流程端侧闭环
华为·harmonyos
李游Leo2 小时前
HarmonyOS 7 HAR + HSP 工程化实战:模块复用、包体积控制与依赖边界
harmonyos
昇腾知识体系3 小时前
鲲鹏+昇腾 NUMA 亲和性调优:Kunpeng 920 双路服务器给 NPU 工作负载绑核
人工智能·华为·知识图谱
用户593096009784 小时前
Flutter 鸿蒙化实战:r_upgrade 适配 OpenHarmony,应用升级检查与弹窗
harmonyos
youyin4 小时前
HarmonyOS 鸿蒙 ArkTS/ArkUI 装饰器大全
华为·harmonyos
轻口味4 小时前
HarmonyOS 7 新特性1:闪控窗——轻规划里的专注倒计时,跟着你走出应用
harmonyos·鸿蒙·移动端·闪控窗
用户593096009785 小时前
Flutter 鸿蒙化实战:record_mp3 适配 OpenHarmony,边录音边出 MP3
harmonyos
youyin5 小时前
HarmonyOS ArkTS 与智能融合案例之实时语音翻译应用 实验指导书和代码
华为·harmonyos
木子雨廷5 小时前
第 16 天|网络四态:loading、error、empty、content
harmonyos
用户593096009785 小时前
Flutter 鸿蒙化实战:open_app_settings 适配 OpenHarmony,一键跳转系统设置
harmonyos