• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# console (日志打印)
2
3本模块提供基础的日志打印能力,支持按照日志级别打印日志信息。
4
5如果需要使用更高级的日志打印服务,比如按照指定标识筛选日志内容,推荐使用[`@ohos.hilog`](js-apis-hilog.md)。
6
7> **说明:**
8>
9> 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
10
11## console.debug
12
13debug(message: string): void
14
15打印debug级别的日志信息。
16
17**系统能力:** SystemCapability.ArkUI.ArkUI.Full
18
19**参数:**
20
21| 参数名     | 类型     | 必填   | 说明          |
22| ------- | ------ | ---- | ----------- |
23| message | string | 是    | 表示要打印的文本信息。 |
24
25
26## console.log
27
28log(message: string): void
29
30打印debug级别的日志信息。
31
32**系统能力:** SystemCapability.ArkUI.ArkUI.Full
33
34**参数:**
35
36| 参数名     | 类型     | 必填   | 说明          |
37| ------- | ------ | ---- | ----------- |
38| message | string | 是    | 表示要打印的文本信息。 |
39
40
41## console.info
42
43info(message: string): void
44
45打印info级别的日志信息。
46
47**系统能力:** SystemCapability.ArkUI.ArkUI.Full
48
49**参数:**
50
51| 参数名     | 类型     | 必填   | 说明          |
52| ------- | ------ | ---- | ----------- |
53| message | string | 是    | 表示要打印的文本信息。 |
54
55
56## console.warn
57
58warn(message: string): void
59
60打印warn级别的日志信息。
61
62**系统能力:** SystemCapability.ArkUI.ArkUI.Full
63
64**参数:**
65
66| 参数名     | 类型     | 必填   | 说明          |
67| ------- | ------ | ---- | ----------- |
68| message | string | 是    | 表示要打印的文本信息。 |
69
70
71## console.error
72
73error(message: string): void
74
75打印error级别的日志信息。
76
77**系统能力:** SystemCapability.ArkUI.ArkUI.Full
78
79**参数:**
80
81| 参数名     | 类型     | 必填   | 说明          |
82| ------- | ------ | ---- | ----------- |
83| message | string | 是    | 表示要打印的文本信息。 |
84
85
86## 示例
87
88```
89export default {
90  clickConsole(){
91    var versionCode = 1;
92    console.info('Hello World. The current version code is ' + versionCode);
93    console.log(`versionCode: ${versionCode}`);
94    // 以下写法从API Version 6开始支持console.log('versionCode:%d.', versionCode);
95  }
96}
97```
98
99在DevEco Studio的底部,切换到“HiLog”窗口。选择当前的设备及进程,日志级别选择Info,搜索内容设置为“Hello World”。此时窗口仅显示符合条件的日志,效果如图所示:
100
101![zh-cn_image_0000001200913929](figures/zh-cn_image_0000001200913929.png)
102