• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Console
2
3The **console** module provides a simple debugging console, which is similar to the JavaScript console provided by the browser.
4
5> **NOTE**
6>
7> 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.
8
9## console.debug
10
11debug(message: string, ...arguments: any[]): void
12
13Prints debugging information in formatted output mode.
14
15**System capability**: SystemCapability.ArkUI.ArkUI.Full
16
17**Parameters**
18
19| Name    | Type    | Mandatory  | Description         |
20| ------- | ------ | ---- | ----------- |
21| message | string | Yes   | Text to be printed.|
22| arguments | any[] | No   | Arguments in the message or other information to be printed.|
23
24**Example**
25
26```js
27const number = 5;
28console.debug('count: %d', number);  // Print the debugging information with arguments in the message replaced.
29// count: 5
30console.debug('count:', number);  // Print the message and other information.
31// count: 5
32console.debug('count:'); // Print the message only.
33// count:
34```
35
36## console.log
37
38log(message: string, ...arguments: any[]): void
39
40Prints log information in formatted output mode.
41
42**System capability**: SystemCapability.ArkUI.ArkUI.Full
43
44**Parameters**
45
46| Name    | Type    | Mandatory  | Description         |
47| ------- | ------ | ---- | ----------- |
48| message | string | Yes   | Text to be printed.|
49| arguments | any[] | No   |Arguments in the message or other information to be printed.|
50
51**Example**
52
53```js
54const number = 5;
55console.log('count: %d', number);  // Print the log information with arguments in the message replaced.
56// count: 5
57console.log('count:', number);  // Print the message and other information.
58// count: 5
59console.log('count:'); // Print the message only.
60// count:
61```
62
63## console.info
64
65info(message: string, ...arguments: any[]): void
66
67Prints log information in formatted output mode. This API is the alias of **console.log ()**.
68
69**System capability**: SystemCapability.ArkUI.ArkUI.Full
70
71**Parameters**
72
73| Name    | Type    | Mandatory  | Description         |
74| ------- | ------ | ---- | ----------- |
75| message | string | Yes   | Text to be printed.|
76| arguments | any[] | No   | Arguments in the message or other information to be printed.|
77
78**Example**
79
80```js
81const number = 5;
82console.info('count: %d', number);  // Print the log information with arguments in the message replaced.
83// count: 5
84console.info('count:', number);  // Print the message and other information.
85// count: 5
86console.info('count:'); // Print the message only.
87// count:
88```
89
90## console.warn
91
92warn(message: string, ...arguments: any[]): void
93
94Prints warning information in formatted output mode.
95
96**System capability**: SystemCapability.ArkUI.ArkUI.Full
97
98**Parameters**
99
100| Name    | Type    | Mandatory  | Description         |
101| ------- | ------ | ---- | ----------- |
102| message | string | Yes   | Warning information to be printed.|
103| arguments | any[] | No   | Arguments in the message or other information to be printed.|
104
105**Example**
106
107```js
108const str = "name should be string";
109console.warn('warn: %d', str); // Print the warning information with arguments in the message replaced.
110// warn: name should be string
111console.warn('warn:', str);  // Print the message and other information.
112// warn: name should be string
113console.warn('warn:'); // Print the message only.
114// warn:
115```
116
117## console.error
118
119error(message: string, ...arguments: any[]): void
120
121Prints error information in formatted output mode.
122
123**System capability**: SystemCapability.ArkUI.ArkUI.Full
124
125**Parameters**
126
127| Name    | Type    | Mandatory  | Description         |
128| ------- | ------ | ---- | ----------- |
129| message | string | Yes   | Error information to be printed.|
130| arguments | any[] | No   | Arguments in the message or other information to be printed.|
131
132
133**Example**
134
135```js
136const str = "value is not defined";
137console.error('error: %d', str);  // Print the error information with arguments in the message replaced.
138// error: value is not defined
139console.error('error:', str);  // Print the message and other information.
140// error: value is not defined
141console.error('error:'); // Print the message only.
142// error:
143```
144