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. 在日志显示中可以筛选日志的打印信息
相关推荐
G_dou_6 小时前
Flutter三方库适配OpenHarmony【habit_tracker】习惯追踪器项目完整实战
flutter·harmonyos
Swift社区6 小时前
鸿蒙游戏自动测试:AI 驱动的测试方案实战
人工智能·游戏·harmonyos
Swift社区6 小时前
鸿蒙 PC 性能监控:原理分析 + 实战工具
harmonyos
阿钱真强道6 小时前
27 鸿蒙LiteOS RK2206 设备连路由器完整实战(配网+联网验证+网络连通性测试)
wifi·harmonyos·鸿蒙·rk·liteos·开源鸿蒙·瑞芯微
网络与设备以及操作系统学习使用者6 小时前
三层交换机实现PC互通方案
运维·网络·学习·华为
yuegu7776 小时前
HarmonyOS应用<节气通>开发第18篇:关于页面与隐私政策
华为·harmonyos
风华圆舞6 小时前
Flutter 项目接入 HarmonyOS 的完整工程结构解析
flutter·华为·harmonyos
●VON6 小时前
AtomGit Flutter鸿蒙客户端:通知系统
flutter·华为·跨平台·harmonyos·鸿蒙
小雨下雨的雨12 小时前
井字棋AI机器人实现详解 - Minimax算法实战-鸿蒙PC Electron框架完成
前端·人工智能·算法·华为·electron·鸿蒙
不爱吃糖的程序媛17 小时前
鸿蒙服务卡片实战:为新华字典应用添加桌面快捷查询卡片
华为·harmonyos