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.
This document describes only API functions. For details about log printing requirements, see [Logging Guide](../../../contribute/OpenHarmony-Log-guide.md).
> **NOTE**<br>
> 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.
| 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.|
| 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.|
| 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,<br>for example, no network signal or login failure.<br>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. |
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.
| 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.|
| 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.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| 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**
```
hilog.info(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0);
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.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 <private>
| 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.|
| 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.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| 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**
```
hilog.warn(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0);
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.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 <private>
| 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.|
| 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.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| 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**
```
hilog.error(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0);
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.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 <private>
| 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.|
| 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.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| 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**
```
hilog.fatal(0xFF00, "testTag", "%d: %{private}s World %{public}f", 1, "hello", 3.0);
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.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 <private>
| 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.<br>Parameters labeled **{public}** are public data and are displayed in plaintext; parameters labeled **{private}** (default value) are private data and are filtered by **<private>**.|
| 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**
```
hilog.isLoggable(0xFF00, "testTag", hilog.DEBUG);
```
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.
## LogLevel
Enumerates event types.
```js
hilog.fatal(0x0001,"testTag","%{public}s World %{private}d","hello",3);
> - The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
>
>
> - The APIs of this module are system APIs and cannot be called by third-party applications.
...
...
@@ -17,66 +18,69 @@ import inputConsumer from '@ohos.multimodalInput.inputConsumer';
Enables listening for combination key events. When a combination key event that meets the specified conditions occurs, **keyOption** will be passed as an input parameter to **callback**.
Enables listening for combination key events. When a combination key event that meets the specified conditions occurs, **KeyOptions** will be passed as an input parameter to **callback**.
| type | string | Yes | Type of the key input event to listen for. Only **key** is supported. |
| keyOption | [KeyOption](#keyoption) | Yes | Key option, which specifies the condition for combination key input. |
| callback | Callback<KeyOption> | Yes | Callback function. When a key input event that meets the specified options occurs, **keyOption** will be passed as an input parameter to **callback**. |
| type | string | Yes| Type of the key input event to listen for. Only **key** is supported.|
| keyOptions | [KeyOptions](#keyoption) | Yes| Key option, which specifies the condition for combination key input.|
| callback | Callback<KeyOptions> | Yes| Callback used to return the result. When a key input event that meets the specified options occurs, **keyOptions** will be passed as an input parameter to **callback**.|
The input device management module is used to listen for the connection, disconnection, and updates of input devices and display information about input devices. For example, it can be used to listen for mouse insertion and removal and obtain information such as the ID, name, and pointer speed of the mouse.
> The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version.
...
...
@@ -59,7 +59,7 @@ Obtains the IDs of all input devices. This API uses a promise to return the resu
**Return value**
| Name | Description |
| Parameter | Description |
| ---------------------- | ------------------ |
| Promise<Array<number>> | Promise used to return the result.|
...
...
@@ -130,7 +130,7 @@ Obtains the information about an input device. This API uses a promise to return
**Return value**
| Name | Description |
| Parameter | Description |
| ------------------------ | ------------------ |
| Promise<InputDeviceData> | Promise used to return the result.|
...
...
@@ -165,11 +165,18 @@ Defines the information about an input device.
| id | number | Unique identifier of an input device. If the same physical device is repeatedly inserted and removed, its ID changes. |
| name | string | Name of the input device. |
| sources | Array<[SourceType](#sourcetype)> | Source types of the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad.|
| id | number | Unique identifier of an input device. If the same physical device is repeatedly inserted and removed, its ID changes.|
| name | string | Name of the input device. |
| sources | Array<[SourceType](#sourcetype)> | Source types of the input device. For example, if a keyboard is attached with a touchpad, the device has two input sources: keyboard and touchpad.|
| axisRanges | Array<[axisRanges](#axisrange)> | Axis information of the input device. |
| bus | number | Bus type of the input device. |
| product | number | Product information of the input device. |
| vendor | number | Vendor information of the input device. |
| version | number | Version information of the input device. |
| phys | string | Physical address of the input device. |
| uniq | string | Unique ID of the input device. |
> - 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.
>
> - The APIs of this module are system APIs and cannot be called by third-party applications.
...
...
@@ -15,7 +15,7 @@ import inputMonitor from '@ohos.multimodalInput.inputMonitor';
@@ -109,7 +109,7 @@ Represents the class of the callback used to return the touch event. The value *
### (touchEvent: TouchEvent): Boolean
Represents the callback used to return the touch event. You need to define the name of the callback function in the correct format. Ensure that the input parameter is of the TouchEvent type, and the return value is of the Boolean type.
Represents the callback used to return the touch event. You need to define the name of the callback function in the correct format. Ensure that the input parameter is of the **TouchEvent** type, and the return value is of the **Boolean** type.
OpenHarmony provides a Natural User Interface \(NUI\) for you to interact with your users. Unlike conventional categorization of input methods, OpenHarmony combines input methods of different dimensions into multimodal inputs, so you can easily arm your application with multi-dimensional, natural interaction features by using the application framework and system built-in UI components or APIs.
OpenHarmony provides a Natural User Interface (NUI) for you to interact with your users. Unlike conventional categorization of input methods, OpenHarmony combines input methods of different dimensions into multimodal inputs, so you can easily arm your application with multi-dimensional, natural interaction features by using the application framework and system built-in UI components or APIs.
Specifically, OpenHarmony currently supports traditional input methods such as key and touch inputs.
Specifically, the Multimodal Input subsystem receives input events from various input devices, such as the keyboard, mouse, touchscreen, and touchpad, via the Linux native driver and HDF driver. After that, it normalizes and standardizes the input events, and distributes the events to the Inner SDK. The Inner SDK distributes the events to the ArkUI framework, which then encapsulates the input events and passes them to applications. Alternatively, the Inner SDK can also directly distribute input events to applications through JsKit APIs.
| Key injection| function injectEvent(keyEvent: KeyEvent): number; | Injects events.|
### Usage Description
Currently, only the **BACK** key event can be injected.
When a system app needs to return to the previous directory, you can call the API to inject the **BACK** key event to Multimodal Input, which then transfers this event to the system app, thereby achieving the return effect. The example code is as follows:
```
// Import the required JavaScript API library.
import inputEventClient from '@ohos.multimodalInput.inputEventClient';
// Call the API for injecting events.
let keyEvent = {
isPressed: true, // Action type of the key event. true indicates that the key is being pressed down, and false indicates that the key is being released.
keyCode: 2, // Keycode for the key, for example, 2 for the BACK key.
keyDownDuration: 0, // Duration in which the current key is pressed down before it is released, in milliseconds.
isIntercepted: false // Whether interception is enabled
}
res = inputEventClient.injectEvent({KeyEvent: keyEvent});