当前位置:   article > 正文

鸿蒙开发系列教程(十六)--日志处理_鸿蒙os ets 日志打印

鸿蒙os ets 日志打印

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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

调用:

import Logger from '../Logger';

Logger.info(`输出内容。。。。。`);
  • 1
  • 2
  • 3
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/245011
推荐阅读
相关标签
  

闽ICP备14008679号