From 2327faa9a99dcd90fad5da7508ab1a345f9c7617 Mon Sep 17 00:00:00 2001 From: yaochaonan Date: Fri, 19 May 2023 06:38:21 +0000 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9console=E6=8F=8F=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yaochaonan --- .../reference/apis/js-apis-console.md | 139 ++++++++++++++++++ .../reference/apis/js-apis-logs.md | 101 ------------- 2 files changed, 139 insertions(+), 101 deletions(-) create mode 100644 zh-cn/application-dev/reference/apis/js-apis-console.md delete mode 100644 zh-cn/application-dev/reference/apis/js-apis-logs.md diff --git a/zh-cn/application-dev/reference/apis/js-apis-console.md b/zh-cn/application-dev/reference/apis/js-apis-console.md new file mode 100644 index 0000000000..815d920ee7 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-console.md @@ -0,0 +1,139 @@ +# console 控制台 + +本模块提供了一个简单的调试控制台,类似于浏览器提供的JavaScript控制台机制。 + +> **说明:** +> +> 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + +## console.debug + +debug(message: string, ...arguments: any[]): void + +以格式化输出方式打印调试信息。 + +**系统能力:** SystemCapability.ArkUI.ArkUI.Full + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------ | ---- | ----------- | +| message | string | 是 | 表示要打印的文本信息。 | +| arguments | any | 否 | 表示其余要打印的信息或message的替换值。 | + +**示例:** +```js +const number = 5; +console.debug('count: %d', number); // 格式化输出替换message中的文本。 +// count: 5 +console.debug('count:', number); // 打印message以及其余信息 +// count: 5 +console.debug('count:'); // 仅打印message +// count: +``` + +## console.log + +log(message: string, ...arguments: any[]): void + +以格式化输出方式打印日志信息。 + +**系统能力:** SystemCapability.ArkUI.ArkUI.Full + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------ | ---- | ----------- | +| message | string | 是 | 表示要打印的文本信息。 | +| arguments | any | 否 |表示其余要打印的信息或message的替换值。 | + +**示例:** +```js +const number = 5; +console.log('count: %d', number); // 格式化输出替换message中的文本。 +// count: 5 +console.log('count:', number); // 打印message以及其余信息 +// count: 5 +console.log('count:'); // 仅打印message +// count: +``` + +## console.info + +info(message: string, ...arguments: any[]): void + +以格式化输出方式打印日志信息。(console.log()的别名)。 + +**系统能力:** SystemCapability.ArkUI.ArkUI.Full + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------ | ---- | ----------- | +| message | string | 是 | 表示要打印的文本信息。 | +| arguments | any | 否 | 表示其余要打印的信息或message的替换值。 | + +**示例:** +```js +const number = 5; +console.info('count: %d', number); // 格式化输出替换message中的文本。 +// count: 5 +console.info('count:', number); // 打印message以及其余信息 +// count: 5 +console.info('count:'); // 仅打印message +// count: +``` + +## console.warn + +warn(message: string, ...arguments: any[]): void + +以格式化输出方式打印警告信息。 + +**系统能力:** SystemCapability.ArkUI.ArkUI.Full + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------ | ---- | ----------- | +| message | string | 是 | 表示要打印的警告信息。 | +| arguments | any | 否 | 表示其余要打印的信息或message的替换值。 | + +**示例:** +```js +const str = "name should be string"; +console.warn('warn: %d', str); // 格式化输出替换message中的文本。 +// warn: name should be string +console.warn('warn:', str); // 打印message以及其余信息 +// warn: name should be string +console.warn('warn:'); // 仅打印message +// warn: +``` + +## console.error + +error(message: string, ...arguments: any[]): void + +以格式化输出方式打印错误信息。 + +**系统能力:** SystemCapability.ArkUI.ArkUI.Full + +**参数:** + +| 参数名 | 类型 | 必填 | 说明 | +| ------- | ------ | ---- | ----------- | +| message | string | 是 | 表示要打印的错误信息。 | +| arguments | any | 否 | 表示其余要打印的信息或message的替换值。 | + + +**示例:** +```js +const str = "value is not defined"; +console.error('error: %d', str); // 格式化输出替换message中的文本。 +// error: value is not defined +console.error('error:', str); // 打印message以及其余信息 +// error: value is not defined +console.error('error:'); // 仅打印message +// error: +``` + diff --git a/zh-cn/application-dev/reference/apis/js-apis-logs.md b/zh-cn/application-dev/reference/apis/js-apis-logs.md deleted file mode 100644 index 40213556ac..0000000000 --- a/zh-cn/application-dev/reference/apis/js-apis-logs.md +++ /dev/null @@ -1,101 +0,0 @@ -# console (日志打印) - -本模块提供基础的日志打印能力,支持按照日志级别打印日志信息。 - -如果需要使用更高级的日志打印服务,比如按照指定标识筛选日志内容,推荐使用[`@ohos.hilog`](js-apis-hilog.md)。 - -> **说明:** -> -> 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 - -## console.debug - -debug(message: string): void - -打印debug级别的日志信息。 - -**系统能力:** SystemCapability.ArkUI.ArkUI.Full - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------ | ---- | ----------- | -| message | string | 是 | 表示要打印的文本信息。 | - - -## console.log - -log(message: string): void - -打印debug级别的日志信息。 - -**系统能力:** SystemCapability.ArkUI.ArkUI.Full - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------ | ---- | ----------- | -| message | string | 是 | 表示要打印的文本信息。 | - - -## console.info - -info(message: string): void - -打印info级别的日志信息。 - -**系统能力:** SystemCapability.ArkUI.ArkUI.Full - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------ | ---- | ----------- | -| message | string | 是 | 表示要打印的文本信息。 | - - -## console.warn - -warn(message: string): void - -打印warn级别的日志信息。 - -**系统能力:** SystemCapability.ArkUI.ArkUI.Full - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------ | ---- | ----------- | -| message | string | 是 | 表示要打印的文本信息。 | - - -## console.error - -error(message: string): void - -打印error级别的日志信息。 - -**系统能力:** SystemCapability.ArkUI.ArkUI.Full - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------ | ---- | ----------- | -| message | string | 是 | 表示要打印的文本信息。 | - - -## 示例 - -``` -export default { - clickConsole(){ - var versionCode = 1; - console.info('Hello World. The current version code is ' + versionCode); - console.log(`versionCode: ${versionCode}`); - // 以下写法从API Version 6开始支持console.log('versionCode:%d.', versionCode); - } -} -``` - -在DevEco Studio的底部,切换到“HiLog”窗口。选择当前的设备及进程,日志级别选择Info,搜索内容设置为“Hello World”。此时窗口仅显示符合条件的日志,效果如图所示: - -![zh-cn_image_0000001200913929](figures/zh-cn_image_0000001200913929.png) -- GitLab