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. 在日志显示中可以筛选日志的打印信息
相关推荐
若兰幽竹3 分钟前
【HarmonyOS 6.1 全场景实战】《灵犀厨房》实战(三):ArkTS 高效开发:TypeScript 核心与 API 23 新规
harmonyos·鸿蒙系统·harmonyos6.1.0
Swift社区5 分钟前
鸿蒙 PC 为什么更像“系统”,而不是“应用平台”?
华为·harmonyos
aqi002 小时前
一文速览 HarmonyOS 6.0.1 引入的十个新特性
android·华为·harmonyos·鸿蒙·harmony
麟听科技2 小时前
HarmonyOS 6.0+ 跨端智能写作助手开发实战:多设备接续编辑与AI辅助创作落地
人工智能·分布式·华为·harmonyos·ai写作
求学中--3 小时前
ArkUI电商首页完整实战
华为·typescript·harmonyos
xmdy58663 小时前
Flutter+开源鸿蒙实战|城市共享驿站智能存取系统 Day1 项目初始化+架构分层+多端适配+全局状态基座
flutter·开源·harmonyos
前端不太难3 小时前
AI 能力如何变成鸿蒙 App 的基础设施
人工智能·状态模式·harmonyos
空中海3 小时前
01 鸿蒙知识体系图与环境基础
华为·harmonyos
三声三视3 小时前
鸿蒙 ArkTS 国际化实战全攻略:多语言切换、格式本地化与 RTL 布局一步到位
华为·harmonyos·鸿蒙
月光技术杂谈4 小时前
openEuler各镜像目录区别、部署差异及5G基站平台稳定高性能系统构建方案
5g·华为·信创·镜像·openeuler·国产·欧拉