提交 cb287f36 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 95046277
# Console
> **NOTE**<br>
> 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:
```
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册