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 分钟前
HarmonyOS 6游戏开发实战:基于悬浮导航与沉浸光感的“光影迷宫“解谜游戏
游戏·华为·harmonyos·悬浮导航·沉浸光感
liulian09161 小时前
Flutter 三方库 connectivity_plus 的鸿蒙化适配与网络状态管理实战
网络·flutter·华为·学习方法·harmonyos
liulian09163 小时前
【Flutter For OpenHarmony】Flutter 三方库 flutter_secure_storage 的鸿蒙化适配指南
flutter·华为·学习方法·harmonyos
liulian09163 小时前
【Flutter For OpenHarmony】Flutter 三方库 flutter_local_notifications 的鸿蒙化适配指南
flutter·华为·学习方法·harmonyos
IntMainJhy4 小时前
【Flutter 三方库 Provider 】flutter for open harmony的鸿蒙化适配与实战指南✨
flutter·华为·harmonyos
Swift社区4 小时前
鸿蒙游戏,会不会重演微信小游戏的爆发?
游戏·微信·harmonyos
前端不太难4 小时前
鸿蒙游戏的 CI/CD 方案
游戏·ci/cd·harmonyos
Lanren的编程日记15 小时前
Flutter鸿蒙应用开发:数据统计与分析功能集成实战
flutter·华为·harmonyos
Swift社区17 小时前
鸿蒙游戏 UI 怎么设计才不乱?
游戏·ui·harmonyos
积水成渊,蛟龙生焉19 小时前
鸿蒙通用事件(事件分发、事件拦截等)
华为·arkts·鸿蒙·事件分发·通用事件·事件拦截