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. 在日志显示中可以筛选日志的打印信息
相关推荐
行者-全栈开发4 小时前
【共创稿事节】HarmonyOS 7 轻量悬浮窗口选型与闪控窗接入:闪控球、闪控窗、系统悬浮窗到底怎么选
harmonyos·鸿蒙·arkui·闪控窗·api 26·选型决策树·闪控球
OH_TPC6 小时前
@ohos/axios 源码解读(二):适配层是一场翻译,而翻译要处理四类错位
harmonyos
fleaxin7 小时前
华为 Atlas 300V 兼容性测试报告
华为·pve·atlas
腾科IT教育9 小时前
HCIP-Security 华为Portal认证技术与配置解析
网络·华为·portal·hcip-security
CV工程师丁Sir11 小时前
ArkWeb 手记 11:Web 组件与原生动画的协同
harmonyos·混合开发·arkweb
李&@杰11 小时前
交换机网络环路导致MAC漂移及业务中断故障处理
网络·华为
CV工程师丁Sir11 小时前
ArkWeb 手记 12:Web 组件内存泄漏排查实录
性能优化·harmonyos·arkweb
用户29469405448161 天前
DSH Desktop - Electron on HarmonyOS Edition
harmonyos·deepseek
IsITGirl1 天前
HarmonyOS 鸿蒙 WuKong 稳定性测试报错 Failed to connect to AAMS(已解决)
华为·harmonyos
万物智能信息科技1 天前
鸿蒙RS232驱动开发—【万物智能之开源鸿蒙OpenHarmony系统实战开发系列教程】
驱动开发·华为·开源·harmonyos·鸿蒙