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. 在日志显示中可以筛选日志的打印信息
相关推荐
鸣弦artha1 小时前
Flutter框架跨平台鸿蒙开发——Widget体系概览
flutter·华为·harmonyos
南村群童欺我老无力.1 小时前
Flutter 框架跨平台鸿蒙开发 - 打造安全可靠的密码生成器,支持强度检测与历史记录
flutter·华为·typescript·harmonyos
鸣弦artha2 小时前
Flutter 框架跨平台鸿蒙开发——Flutter引擎层架构概览
flutter·架构·harmonyos
时光慢煮4 小时前
基于 Flutter × OpenHarmony 图书馆管理系统之构建搜索栏
flutter·华为·开源·openharmony
鸣弦artha5 小时前
Flutter框架跨平台鸿蒙开发——StatelessWidget基础
flutter·华为·harmonyos
夜雨声烦丿5 小时前
Flutter 框架跨平台鸿蒙开发 - 打造习惯打卡应用,连续天数统计与热力图展示
flutter·华为·harmonyos
南村群童欺我老无力.6 小时前
Flutter 框架跨平台鸿蒙开发 - 开发二维码生成器与扫描器
flutter·华为·typescript·harmonyos
南村群童欺我老无力.6 小时前
Flutter 框架跨平台鸿蒙开发 - 喝水提醒应用开发指南
flutter·华为·harmonyos
奋斗的小青年!!6 小时前
Flutter开发鸿蒙应用实战:位置分享组件的跨平台实现
flutter·harmonyos·鸿蒙
鸣弦artha6 小时前
Flutter框架跨平台鸿蒙开发——Embedding层架构概览
flutter·embedding·harmonyos