diff --git a/en/application-dev/reference/apis/js-apis-hilog.md b/en/application-dev/reference/apis/js-apis-hilog.md index b718eb04862f6795ff8d8d95763ce173f0839257..4d45271a8791a8370ed4950c75ac96c0fb408b8c 100644 --- a/en/application-dev/reference/apis/js-apis-hilog.md +++ b/en/application-dev/reference/apis/js-apis-hilog.md @@ -1,6 +1,8 @@ # HiLog -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
+The HiLog subsystem allows your applications or services to output logs based on the specified type, level, and format string. Such logs help you learn the running status of applications and better debug programs. + +> **NOTE**
> The initial APIs of this module are supported since API version 7. Newly added APIs will be marked with a superscript to indicate their earliest API version. ## Modules to Import @@ -9,184 +11,201 @@ import hilog from '@ohos.hilog'; ``` +## hilog.isLoggable -## hilog.debug - -debug(domain: number, tag: string, format: string, ...args: any[]) : void +isLoggable(domain: number, tag: string, level: LogLevel) : boolean -Prints logs of the DEBUG level. +Checks whether logs are printable based on the specified service domain, log tag, and log level. **System capability**: SystemCapability.HiviewDFX.HiLog **Parameters** -| Name| Type | Mandatory | Description | -| ------ | -------------- | ---- | ------------------------------------------------------------ | -| domain | number | Yes | Service domain. The value ranges from **0x0** to **0xFFFFF**. | -| tag | string | Yes | String constant used to identify the class or service behavior. | -| format | string | Yes | String constant format, including the parameter type and privacy identifier. A parameter without the privacy identifier is treated as a privacy parameter by default. | -| args | any[] | Yes | Variable-length parameter list corresponding to the parameter type in the format string. The number and type of parameters must map to the identifier in the format string. | +| Name| Type | Mandatory| Description | +| ------ | --------------------- | ---- | ------------------------------------------------------------ | +| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| +| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| +| level | [LogLevel](#loglevel) | Yes | Log level. | + +**Return value** + +| Type | Description | +| ------- | ------------------------------------------------------------ | +| boolean | Returns **true** logs are printable based on the specified service domain, log tag, and log level; returns **false** otherwise.| **Example** ```js -hilog.debug(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0); +hilog.isLoggable(0x0001, "testTag", hilog.LogLevel.INFO); ``` -**Output** +## LogLevel -``` -09-08 12:49:35.941 1547 2452 D FF00/testTag: 1: hello World 3.0 -``` +Enumerates the log levels. -## hilog.info +**System capability**: SystemCapability.HiviewDFX.HiLog -info(domain: number, tag: string, format: string, ...args: any[]) : void +| Name | Default Value| Description | +| ----- | ------ | ------------------------------------------------------------ | +| DEBUG | 3 | Log level used to record more detailed process information than INFO logs to help developers analyze service processes and locate faults.| +| INFO | 4 | Log level used to record key service process nodes and exceptions that occur during service running,
for example, no network signal or login failure.
These logs should be recorded by the dominant module in the service to avoid repeated logging conducted by multiple invoked modules or low-level functions.| +| WARN | 5 | Log level used to record severe, unexpected faults that have little impact on users and can be rectified by the programs themselves or through simple operations.| +| ERROR | 6 | Log level used to record program or functional errors that affect the normal running or use of the functionality and can be fixed at a high cost, for example, by resetting data.| +| FATAL | 7 | Log level used to record program or functionality crashes that cannot be rectified. | + +## hilog.debug + +debug(domain: number, tag: string, format: string, ...args: any[]) : void -Prints logs of the INFO level. +Prints DEBUG logs. + +DEBUG logs are not recorded in official versions by default. They are available in debug versions or in official versions with the debug function enabled. **System capability**: SystemCapability.HiviewDFX.HiLog **Parameters** -| Name| Type | Mandatory | Description | -| ------ | -------------- | ---- | ------------------------------------------------------------ | -| domain | number | Yes | Service domain. The value ranges from **0x0** to **0xFFFFF**. | -| tag | string | Yes | String constant used to identify the class or service behavior. | -| format | string | Yes | String constant format, including the parameter type and privacy identifier. A parameter without the privacy identifier is treated as a privacy parameter by default. | -| args | any[] | Yes | Variable-length parameter list corresponding to the parameter type in the format string. The number and type of parameters must map to the identifier in the format string. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| +| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| +| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.
Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by ****.| +| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| **Example** +This example is used to output a DEBUG log with the format string being `"%{public}s World %{private}d"`. The variable `%{public}s` is a plaintext string, and the variable `%{private}d` is a private integer. + ```js -hilog.info(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0); +hilog.debug(0x0001, "testTag", "%{public}s World %{private}d", "hello", 3); ``` -**Output** +If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log is as follows: ``` -09-08 12:49:35.941 1547 2452 I FF00/testTag: 1: hello World 3.0 +08-05 12:21:47.579 2695-2703/com.example.myapplication D 00001/testTag: hello World ``` -## hilog.warn +## hilog.info -warn(domain: number, tag: string, format: string, ...args: any[]) : void +info(domain: number, tag: string, format: string, ...args: any[]) : void -Prints logs of the WARN level. +Prints INFO logs. **System capability**: SystemCapability.HiviewDFX.HiLog **Parameters** -| Name| Type | Mandatory | Description | -| ------ | -------------- | ---- | ------------------------------------------------------------ | -| domain | number | Yes | Service domain. The value ranges from **0x0** to **0xFFFFF**. | -| tag | string | Yes | String constant used to identify the class or service behavior. | -| format | string | Yes | String constant format, including the parameter type and privacy identifier. A parameter without the privacy identifier is treated as a privacy parameter by default. | -| args | any[] | Yes | Variable-length parameter list corresponding to the parameter type in the format string. The number and type of parameters must map to the identifier in the format string. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| +| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| +| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.
Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by ****.| +| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| **Example** +This example is used to output an INFO log with the format string being `"%{public}s World %{private}d"`. The variable `%{public}s` is a plaintext string, and the variable `%{private}d` is a private integer. + ```js -hilog.warn(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0); +hilog.info(0x0001, "testTag", "%{public}s World %{private}d", "hello", 3); ``` -**Output** +If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log is as follows: ``` -09-08 12:49:35.941 1547 2452 W FF00/testTag: 1: hello World 3.0 +08-05 12:21:47.579 2695-2703/com.example.myapplication I 00001/testTag: hello World ``` -## hilog.error +## hilog.warn -error(domain: number, tag: string, format: string, ...args: any[]) : void +warn(domain: number, tag: string, format: string, ...args: any[]) : void -Prints logs of the ERROR level. +Prints WARN logs. **System capability**: SystemCapability.HiviewDFX.HiLog **Parameters** -| Name| Type | Mandatory | Description | -| ------ | -------------- | ---- | ------------------------------------------------------------ | -| domain | number | Yes | Service domain. The value ranges from **0x0** to **0xFFFFF**. | -| tag | string | Yes | String constant used to identify the class or service behavior. | -| format | string | Yes | String constant format, including the parameter type and privacy identifier. A parameter without the privacy identifier is treated as a privacy parameter by default. | -| args | any[] | Yes | Variable-length parameter list corresponding to the parameter type in the format string. The number and type of parameters must map to the identifier in the format string. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| +| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| +| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.
Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by ****.| +| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| **Example** +This example is used to output a WARN log with the format string being `"%{public}s World %{private}d"`. The variable `%{public}s` is a plaintext string, and the variable `%{private}d` is a private integer. + ```js -hilog.error(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0); +hilog.warn(0x0001, "testTag", "%{public}s World %{private}d", "hello", 3); ``` -**Output** +If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log is as follows: ``` -09-08 12:49:35.941 1547 2452 E FF00/testTag: 1: hello World 3.0 +08-05 12:21:47.579 2695-2703/com.example.myapplication W 00001/testTag: hello World ``` -## hilog.fatal +## hilog.error -fatal(domain: number, tag: string, format: string, ...args: any[]) : void +error(domain: number, tag: string, format: string, ...args: any[]) : void -Prints logs of the FATAL level. +Prints ERROR logs. **System capability**: SystemCapability.HiviewDFX.HiLog **Parameters** -| Name| Type | Mandatory | Description | -| ------ | -------------- | ---- | ------------------------------------------------------------ | -| domain | number | Yes | Service domain. The value ranges from **0x0** to **0xFFFFF**. | -| tag | string | Yes | String constant used to identify the class or service behavior. | -| format | string | Yes | String constant format, including the parameter type and privacy identifier. A parameter without the privacy identifier is treated as a privacy parameter by default. | -| args | any[] | Yes | Variable-length parameter list corresponding to the parameter type in the format string. The number and type of parameters must map to the identifier in the format string. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| +| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| +| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.
Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by ****.| +| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| **Example** +This example is used to output an ERROR log with the format string being `"%{public}s World %{private}d"`. The variable `%{public}s` is a plaintext string, and the variable `%{private}d` is a private integer. + ```js -hilog.fatal(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0); +hilog.error(0x0001, "testTag", "%{public}s World %{private}d", "hello", 3); ``` -**Output** +If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log is as follows: ``` -09-08 12:49:35.941 1547 2452 F FF00/testTag: 1: hello World 3.0 +08-05 12:21:47.579 2695-2703/com.example.myapplication E 00001/testTag: hello World ``` -## hilog.isLoggable +## hilog.fatal -isLoggable(domain: number, tag: string, level: LogLevel) : boolean +fatal(domain: number, tag: string, format: string, ...args: any[]) : void -Checks whether printing is enabled for a domain, tag, or log level. +Prints FATAL logs. **System capability**: SystemCapability.HiviewDFX.HiLog **Parameters** -| Name| Type | Mandatory | Description | -| ------ | --------------------- | ---- | ------------------------------------------ | -| domain | number | Yes | Service domain. The value ranges from **0x0** to **0xFFFFF**. | -| tag | string | Yes | String constant used to identify the class or service behavior. | -| level | [LogLevel](#loglevel) | Yes | Log level. | +| Name| Type | Mandatory| Description | +| ------ | ------ | ---- | ------------------------------------------------------------ | +| domain | number | Yes | Service domain of logs. The value ranges from **0x0** to **0xFFFF**. You can define the value as required.| +| tag | string | Yes | Log tag in the string format. You are advised to use this parameter to identify a particular service behavior or the class holding the ongoing method.| +| format | string | Yes | Format string used to output logs in a specified format. It can contain several parameters, where the parameter type and privacy identifier are mandatory.
Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by ****.| +| args | any[] | Yes | Variable-length parameter list corresponding to the format string. The number and type of parameters must map to the identifier in the format string.| **Example** +This example is used to output a FATAL log with the format string being `"%{public}s World %{private}d"`. The variable `%{public}s` is a plaintext string, and the variable `%{private}d` is a private integer. + ```js -hilog.isLoggable(0xFF00, "testTag", hilog.DEBUG); +hilog.fatal(0x0001, "testTag", "%{public}s World %{private}d", "hello", 3); ``` -## LogLevel +If `"hello"` is filled in `%{public}s` and `3` in `%{private}d`, the output log is as follows: -Enumerates event types. - -**System capability**: SystemCapability.HiviewDFX.HiLog - -| Name | Default Value | Description | -| ----- | ------ | ----------- | -| DEBUG | 3 | DEBUG level | -| INFO | 4 | INFO level | -| WARN | 5 | WARN level | -| ERROR | 6 | ERROR level | -| FATAL | 7 | FATAL level | +``` +08-05 12:21:47.579 2695-2703/com.example.myapplication F 00001/testTag: hello World +``` diff --git a/en/application-dev/reference/apis/js-apis-radio.md b/en/application-dev/reference/apis/js-apis-radio.md index 5d522a2f1b12bbb9957fde9c9c9e8c9d681ba205..86d29eebedf8fb206589a7770a92362a79873c69 100644 --- a/en/application-dev/reference/apis/js-apis-radio.md +++ b/en/application-dev/reference/apis/js-apis-radio.md @@ -408,7 +408,7 @@ Checks whether the current device supports 5G \(NR\). ```js let slotId = 0; let result = radio.isNrSupported(slotId); -console.log("result is "+ result); +console.log("Result: "+ result); ``` diff --git a/en/application-dev/reference/apis/js-apis-sim.md b/en/application-dev/reference/apis/js-apis-sim.md index 59900177e69ce5d8649cc5420346f989828936fc..3344e47d14f8d615b1f81e75f92251dc4e8c8287 100644 --- a/en/application-dev/reference/apis/js-apis-sim.md +++ b/en/application-dev/reference/apis/js-apis-sim.md @@ -521,7 +521,7 @@ Obtains the number of card slots. **Example** ```js -console.log("the result is "+sim.getMaxSimCount()) +console.log("Result: "+ sim.getMaxSimCount()) ``` diff --git a/en/application-dev/reference/apis/js-apis-webSocket.md b/en/application-dev/reference/apis/js-apis-webSocket.md index edf6be53ac623c5fa4a8f1542bf7222dc42e713c..52f5367110bc35c33075ed291a796a657a468816 100644 --- a/en/application-dev/reference/apis/js-apis-webSocket.md +++ b/en/application-dev/reference/apis/js-apis-webSocket.md @@ -23,7 +23,7 @@ import webSocket from '@ohos.net.webSocket'; var defaultIpAddress = "ws://"; let ws = webSocket.createWebSocket(); ws.on('open', (err, value) => { - console.log("on open, status:" + value.status + ", message:" + value.message); + console.log("on open, status:" + value['status'] + ", message:" + value['message']); // When receiving the on('open') event, the client can use the send() API to communicate with the server. ws.send("Hello, server!", (err, value) => { if (!err) { @@ -47,7 +47,7 @@ ws.on('message', (err, value) => { } }); ws.on('close', (err, value) => { - console.log("on close, code is " + value.code + ", reason is " + value.reason); + console.log("on close, code is " + value['code'] + ", reason is " + value['reason']); }); ws.on('error', (err) => { console.log("on error, error:" + JSON.stringify(err)); @@ -393,7 +393,7 @@ Enables listening for the **open** events of a WebSocket connection. This API us ```js let ws = webSocket.createWebSocket(); ws.on('open', (err, value) => { - console.log("on open, status:" + value.status + ", message:" + value.message); + console.log("on open, status:" + value['status'] + ", message:" + value['message']); }); ``` @@ -421,7 +421,7 @@ Disables listening for the **open** events of a WebSocket connection. This API u ```js let ws = webSocket.createWebSocket(); let callback1 = (err, value) => { - console.log("on open, status:" + value.status + ", message:" + value.message); + console.log("on open, status:" + value['status'] + ", message:" + value['message']); } ws.on('open', callback1); // You can pass the callback of the on function to cancel listening for a certain type of callback. If you do not pass the callback, you will cancel listening for all callbacks. @@ -505,7 +505,7 @@ Enables listening for the **close** events of a WebSocket connection. This API u ```js let ws = webSocket.createWebSocket(); ws.on('close', (err, value) => { - console.log("on close, code is " + value.code + ", reason is " + value.reason); + console.log("on close, code is " + value['code'] + ", reason is " + value['reason']); }); ```