当前位置: 首页 > article >正文

鸿蒙开发系列教程(十六)--日志处理

console控制台输出

以格式化输出方式打印调试信息
console.debug()
console.debug(‘debug。。。’ )

以格式化输出方式打印日志信息
console.log()
console.log(‘info。。。’)

以格式化输出方式打印警告信息
console.warn()

输出信息
console.info()

注意:输出字符串+变量

console.info(`Aceaaa${JSON.stringify(oldValue)} `)

一定注意引号是英文下的“`” ,即ESC下的"```"

自定义日志

新建logger.ets 文件
导入鸿蒙基础库
import hilog from ‘@ohos.hilog’;

import hilog from '@ohos.hilog';
class Logger {
  private domain: number;
  private prefix: string;
  private format: string = '%{public}s, %{public}s';

  constructor(prefix: string = 'MyApp', domain: number = 0xFF00) {
    this.prefix = prefix;
    this.domain = domain;
  }

  debug(...args: string[]): void {
    hilog.debug(this.domain, this.prefix, this.format, args);
  }

  info(...args: string[]): void {
    hilog.info(this.domain, this.prefix, this.format, args);
  }

  warn(...args: string[]): void {
    hilog.warn(this.domain, this.prefix, this.format, args);
  }

  error(...args: string[]): void {
    hilog.error(this.domain, this.prefix, this.format, args);
  }
}

export default new Logger('[OxHornCampus]', 0xFF00)

调用:

import Logger from '../Logger';

Logger.info(`输出内容。。。。。`);

http://www.kler.cn/a/231020.html

相关文章:

  • java springBoot项目实现数据脱敏的策略
  • qt QMessagbox的按钮的顺序
  • 洛谷_P5461 赦免战俘_python写法
  • Win32 SDK Gui编程系列之--ListView自绘OwnerDraw(续)
  • 黑马Java——集合进阶(List、Set、泛型、树)
  • C++服务器端开发(1):设计服务器架构
  • 使用python启动一个roslaunch文件
  • c#内置委托
  • 最新AI系统ChatGPT网站H5系统源码,支持Midjourney绘画局部编辑重绘,GPT语音对话+ChatFile文档对话总结+DALL-E3文生图
  • 对接快团团,如何快速高效对接快团团大团长?
  • 编程笔记 html5cssjs 075 Javascript 常量和变量
  • 使用 Visual Studio Code 在远程计算机上调试 PostgreSQL
  • FMECA实施步骤——FMEA软件
  • 2.5学习总结9
  • 电商数据采集:选择爬虫工具还是第三方API?
  • HarmonyOS 鸿蒙应用开发(十、第三方开源js库移植适配指南)
  • 构建中国人自己的私人GPT—支持中文
  • 机顶盒晶晨s905l3b芯片刷第三方系统+安卓9 root教程+armbian写入EMMC教程
  • CloudStack Agent重新安装与卸载指南
  • 【机器学习】机器学习流程之收集数据