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 天前
鸿蒙Next ArkWeb网页交互管理:从基础到高级实战
华为·交互·harmonyos
爱笑的眼睛111 天前
HarmonyOS 应用开发:深入剖析声明式 UI 状态管理及其最佳实践
华为·harmonyos
SmartBrain1 天前
DeerFlow实践:华为LTC流程的评审智能体设计
华为·语言模型
猫林老师1 天前
HarmonyOS多媒体开发:音视频播放与录制全解析
华为·音视频·harmonyos
程序员潘Sir1 天前
鸿蒙应用开发从入门到实战(四):ArkTS 语言概述
harmonyos·鸿蒙
爱笑的眼睛111 天前
HarmonyOS 应用开发深度解析:基于 ArkTS 的现代化状态管理实践
华为·harmonyos
娅娅梨1 天前
HarmonyOS-ArkUI Web控件基础铺垫7-HTTP SSL认证图解 及 Charles抓包原理 及您为什么配置对了也抓不到数据
http·华为·ssl·harmonyos
安卓开发者1 天前
鸿蒙NEXT的Web组件网络安全与隐私保护实践
前端·web安全·harmonyos
广州腾科助你拿下华为认证2 天前
华为HCIE-云计算培训课程有哪些?
华为·云计算·hcie认证