From cb287f369413b75a3194355820f682ce757f42e0 Mon Sep 17 00:00:00 2001 From: shawn_he Date: Fri, 9 Jun 2023 16:42:36 +0800 Subject: [PATCH] update doc Signed-off-by: shawn_he --- .../reference/apis/js-apis-logs.md | 152 ++++++++++++------ 1 file changed, 107 insertions(+), 45 deletions(-) diff --git a/en/application-dev/reference/apis/js-apis-logs.md b/en/application-dev/reference/apis/js-apis-logs.md index 6a38125c09..673a24f334 100644 --- a/en/application-dev/reference/apis/js-apis-logs.md +++ b/en/application-dev/reference/apis/js-apis-logs.md @@ -1,81 +1,143 @@ # Console -> **NOTE**
-> The APIs of this module are no longer maintained since API version 7. You are advised to use ['@ohos.hilog](js-apis-hilog.md)' instead. +The **console** module provides a simple debugging console, which is similar to the JavaScript console provided by the browser. + +> **NOTE** +> +> The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## console.debug -debug(message: string): void +debug(message: string, ...arguments: any[]): void + +Prints debugging information in formatted output mode. + +**System capability**: SystemCapability.ArkUI.ArkUI.Full -Prints debug logs. +**Parameters** -- Parameters - | Name | Type | Mandatory | Description | - | ------- | ------ | ---- | ----------- | - | message | string | Yes | Text to print.| +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ----------- | +| message | string | Yes | Text to be printed.| +| arguments | any[] | No | Arguments in the message or other information to be printed.| +**Example** + +```js +const number = 5; +console.debug('count: %d', number); // Print the debugging information with arguments in the message replaced. +// count: 5 +console.debug('count:', number); // Print the message and other information. +// count: 5 +console.debug('count:'); // Print the message only. +// count: +``` ## console.log -log(message: string): void +log(message: string, ...arguments: any[]): void -Prints debug logs. +Prints log information in formatted output mode. -- Parameters - | Name | Type | Mandatory | Description | - | ------- | ------ | ---- | ----------- | - | message | string | Yes | Text to print.| +**System capability**: SystemCapability.ArkUI.ArkUI.Full +**Parameters** + +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ----------- | +| message | string | Yes | Text to be printed.| +| arguments | any[] | No |Arguments in the message or other information to be printed.| + +**Example** + +```js +const number = 5; +console.log('count: %d', number); // Print the log information with arguments in the message replaced. +// count: 5 +console.log('count:', number); // Print the message and other information. +// count: 5 +console.log('count:'); // Print the message only. +// count: +``` ## console.info -info(message: string): void +info(message: string, ...arguments: any[]): void + +Prints log information in formatted output mode. This API is the alias of **console.log ()**. -Prints info-level logs. +**System capability**: SystemCapability.ArkUI.ArkUI.Full -- Parameters - | Name | Type | Mandatory | Description | - | ------- | ------ | ---- | ----------- | - | message | string | Yes | Text to print.| +**Parameters** +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ----------- | +| message | string | Yes | Text to be printed.| +| arguments | any[] | No | Arguments in the message or other information to be printed.| + +**Example** + +```js +const number = 5; +console.info('count: %d', number); // Print the log information with arguments in the message replaced. +// count: 5 +console.info('count:', number); // Print the message and other information. +// count: 5 +console.info('count:'); // Print the message only. +// count: +``` ## console.warn -warn(message: string): void +warn(message: string, ...arguments: any[]): void + +Prints warning information in formatted output mode. + +**System capability**: SystemCapability.ArkUI.ArkUI.Full -Prints warn-level logs. +**Parameters** -- Parameters - | Name | Type | Mandatory | Description | - | ------- | ------ | ---- | ----------- | - | message | string | Yes | Text to print.| +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ----------- | +| message | string | Yes | Warning information to be printed.| +| arguments | any[] | No | Arguments in the message or other information to be printed.| +**Example** + +```js +const str = "name should be string"; +console.warn('warn: %d', str); // Print the warning information with arguments in the message replaced. +// warn: name should be string +console.warn('warn:', str); // Print the message and other information. +// warn: name should be string +console.warn('warn:'); // Print the message only. +// warn: +``` ## console.error -error(message: string): void +error(message: string, ...arguments: any[]): void -Prints error-level logs. +Prints error information in formatted output mode. -- Parameters - | Name | Type | Mandatory | Description | - | ------- | ------ | ---- | ----------- | - | message | string | Yes | Text to print.| +**System capability**: SystemCapability.ArkUI.ArkUI.Full +**Parameters** -## Example +| Name | Type | Mandatory | Description | +| ------- | ------ | ---- | ----------- | +| message | string | Yes | Error information to be printed.| +| arguments | any[] | No | Arguments in the message or other information to be printed.| -``` -export default { - clickConsole(){ - var versionCode = 1; - console.info('Hello World. The current version code is ' + versionCode); - console.log(`versionCode: ${versionCode}`); - / / The following is supported since API version 6: console.log('versionCode:%d.', versionCode); - } -} -``` -Switch to the HiLog window at the bottom of HUAWEI DevEco Studio. Specifically, select the current device and process, set the log level to Info, and enter Hello World in the search box. Logs that meet the search criteria are displayed, as shown in the following figure. +**Example** -![en-us_image_0000001200913929](figures/en-us_image_0000001200913929.png) +```js +const str = "value is not defined"; +console.error('error: %d', str); // Print the error information with arguments in the message replaced. +// error: value is not defined +console.error('error:', str); // Print the message and other information. +// error: value is not defined +console.error('error:'); // Print the message only. +// error: +``` -- GitLab