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. harmonyOS开发技巧(一)——封装hilog日志

    2024-04-23 08:10:03       36 阅读
  2. HarmonyOS系统开发ArkTS基础编程语法

    2024-04-23 08:10:03       24 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-23 08:10:03       19 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-23 08:10:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-23 08:10:03       20 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-23 08:10:03       20 阅读

热门阅读

  1. asio之地址

    2024-04-23 08:10:03       14 阅读
  2. 密码学系列1-安全规约

    2024-04-23 08:10:03       14 阅读
  3. JVM加载类的流程

    2024-04-23 08:10:03       13 阅读
  4. JVM中的堆和栈

    2024-04-23 08:10:03       13 阅读
  5. 掌控基础设施,加速 DevOps 之旅:IaC 深度解析

    2024-04-23 08:10:03       12 阅读
  6. Web 常见十大漏洞原理及利用方式

    2024-04-23 08:10:03       15 阅读
  7. 2024年深圳杯&东三省数学建模联赛赛题浅析

    2024-04-23 08:10:03       16 阅读
  8. STM32 J-LINK

    2024-04-23 08:10:03       16 阅读
  9. 张量堆叠函数torch.stack()

    2024-04-23 08:10:03       10 阅读