1e41f4b71Sopenharmony_ci# HiSysEvent Logging Configuration 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Overview 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci### Function Introduction 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ciIf HiSysEvent logging is required for a component, you need to define a YAML file and [configure the YAML file path](#verifying-the-yaml-file) in the **bundle.json** file. During compilation, the OpenHarmony compilation framework will use the Python compilation script to parse and verify all the YAML files configured in the **bundle.json** file. On completion, the compilation framework will summarize the configuration information in the YAML files and convert the information into a zip file named **hisysevent.zip**. After that, the compilation framework will put the zip file to a specified path as the basis for the system to determine whether to log system events. 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci 12e41f4b71Sopenharmony_ci### Basic Concepts 13e41f4b71Sopenharmony_ci 14e41f4b71Sopenharmony_ciUnderstanding the following concepts would be helpful for you in configuring HiSysEvent logging. 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci- Event domain<br>Represents the domain to which an event belongs. It is specified by the **domain** field in the YAML file. For details, see [domain](#writing-a-yaml-file) in the example YAML file. 17e41f4b71Sopenharmony_ci 18e41f4b71Sopenharmony_ci- Event name<br>Indicates the events in an event domain. For details, see [EVENT\_NAMEA/EVENT\_NAMEB](#writing-a-yaml-file) in the example YAML file. 19e41f4b71Sopenharmony_ci 20e41f4b71Sopenharmony_ci- Parameter<br>Defines the key values in an event name. For details, see [__BASE/NAME1/NAME2](#writing-a-yaml-file) in the example YAML file. 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci### Constraints 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ciConstraints on the event domain, event name, and parameter 26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci- Each YAML file can contain only one event domain, and the domain name cannot be the same as that defined in other YAML files. 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci- Zero or more event names can be defined for one event domain. The event names in the same event domain must be unique. 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci- Multiple parameters can be defined for one event name. The parameters in the same event name must be unique. There must be only one parameter named **\__BASE** in each event name. See Table 1 for the fields of this parameter and Table 2 for the fields of other custom parameters. 32e41f4b71Sopenharmony_ci **Table 1** Fields in the \__BASE parameter 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_ci | Field| Description| 35e41f4b71Sopenharmony_ci | -------- | -------- | 36e41f4b71Sopenharmony_ci | type | Event type. This field is mandatory.<br>Value:<br>- **FAULT**: fault<br>- STATISTIC: statistics<br>- **SECURITY**: security<br>- **BEHAVIOR**: behavior| 37e41f4b71Sopenharmony_ci | level | Event level. This field is mandatory.<br>Value:<br>- CRITICAL: critical<br>- MINOR: minor| 38e41f4b71Sopenharmony_ci | tag | Event tag. This field is mandatory.<br>Rule:<br>- You can define a maximum of five tags, separated with a space.<br>- A single tag can contain a maximum of 16 characters, including a to z, A to Z, and 0 to 9.| 39e41f4b71Sopenharmony_ci | desc | Event name. This field is mandatory.<br>Rule:<br>- A string of 3 to 128 characters.| 40e41f4b71Sopenharmony_ci | preserve | Whether events need to be logged in the event file. This field is optional. The default value is **true**.<br>Value:<br>- **true**: Events need to be logged in the event file.<br>- **false**: Events do not need to be logged in the event file.| 41e41f4b71Sopenharmony_ci 42e41f4b71Sopenharmony_ci **Table 2** Description of custom parameters 43e41f4b71Sopenharmony_ci 44e41f4b71Sopenharmony_ci | Field| Description| 45e41f4b71Sopenharmony_ci | -------- | -------- | 46e41f4b71Sopenharmony_ci | type | Parameter type. This field is mandatory.<br>Value:<br>- BOOL<br>- INT8<br>- UINT8<br>- INT16<br>- UINT16<br>- INT32<br>- UINT32<br>- INT64<br>- UINT64<br>- FLOAT<br>- DOUBLE<br>- STRING | 47e41f4b71Sopenharmony_ci | arrsize | Length of the parameter of the array type. This field is optional.<br>Value:<br>1-100| 48e41f4b71Sopenharmony_ci | desc | Parameter description. This field is mandatory.<br>Rule:<br>- A string of 3 to 128 characters.| 49e41f4b71Sopenharmony_ci 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci## How to Develop 52e41f4b71Sopenharmony_ci 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci### Writing a YAML File 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci 57e41f4b71Sopenharmony_ci**Writing Rules** 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci- Event domain naming rules: 60e41f4b71Sopenharmony_ci - The name must start with a letter and can contain only uppercase letters, digits, and underscores (_). 61e41f4b71Sopenharmony_ci - The name contains 1 to 16 characters. 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ci- Event naming rules: 64e41f4b71Sopenharmony_ci - The name must start with a letter and can contain only uppercase letters, digits, and underscores (_). 65e41f4b71Sopenharmony_ci - The name contains 1 to 32 characters. 66e41f4b71Sopenharmony_ci - The number of internal event names in an event domain cannot exceed 4096. 67e41f4b71Sopenharmony_ci 68e41f4b71Sopenharmony_ci- Parameter naming rules: 69e41f4b71Sopenharmony_ci - The name must start with a letter and can contain only uppercase letters, digits, and underscores (_). 70e41f4b71Sopenharmony_ci - The name contains 1 to 48 characters. 71e41f4b71Sopenharmony_ci - The number of parameters in an event domain cannot exceed 128. 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ci**Example** 75e41f4b71Sopenharmony_ci 76e41f4b71Sopenharmony_ci- In the example YAML file, the event domain name is **MODULEA**. The event domain contains two events named **EVENT_NAMEA** and **EVENT_NAMEB**. 77e41f4b71Sopenharmony_ci 78e41f4b71Sopenharmony_ci- **EVENT\_NAMEA** is defined as a critical event of the fault type. The event contains the **NAME1** parameter of the string type, the **NAME2** parameter of the string type, and the **NAME3** parameter of the unsigned short integer type. Therefore, you can perform [real-time subscription](../subsystems/subsys-dfx-hisysevent-listening.md) to the event based on the event domain **MODULEA** and event name **EVENT\_NAMEA**. 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci- **EVENT\_NAMEB** is defined as a general event of the statistics type. The event contains the **NAME1** parameter of the unsigned short integer type and the **NAME2** parameter of the integer type. Because two event tags named **tag1** and **tag2** are defined for **EVENT\_NAMEB** in the **\__BASE** parameter, you can perform [real-time subscription](../subsystems/subsys-dfx-hisysevent-listening.md) to the event based on the event domain **MODULEA** and event name **EVENT\_NAMEB**, or based on the event tag. 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_ci ``` 83e41f4b71Sopenharmony_ci ########################################## 84e41f4b71Sopenharmony_ci # the hisysevent definition for module a # 85e41f4b71Sopenharmony_ci ########################################## 86e41f4b71Sopenharmony_ci 87e41f4b71Sopenharmony_ci domain: MODULEA 88e41f4b71Sopenharmony_ci 89e41f4b71Sopenharmony_ci EVENT_NAMEA: 90e41f4b71Sopenharmony_ci __BASE: {type: FAULT, level: CRITICAL, desc: event name a} 91e41f4b71Sopenharmony_ci NAME1: {type: STRING, desc: name1} 92e41f4b71Sopenharmony_ci NAME2: {type: STRING, desc: name2} 93e41f4b71Sopenharmony_ci NAME3: {type: UINT16, desc: name3} 94e41f4b71Sopenharmony_ci 95e41f4b71Sopenharmony_ci EVENT_NAMEB: 96e41f4b71Sopenharmony_ci __BASE: {type: STATISTIC, level: MINOR, tag: tag1 tag2, desc: event name b} 97e41f4b71Sopenharmony_ci NAME1: {type: UINT16, desc: name1} 98e41f4b71Sopenharmony_ci NAME2: {type: INT32, desc: name2} 99e41f4b71Sopenharmony_ci ``` 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci 102e41f4b71Sopenharmony_ci### Verifying the YAML File 103e41f4b71Sopenharmony_ci 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ci**Configuring the YAML File Path** 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ciIn the **bundle.json** file, use the **hisysevent_config** attribute to specify the YAML file path. 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci 110e41f4b71Sopenharmony_ci``` 111e41f4b71Sopenharmony_ci{ 112e41f4b71Sopenharmony_ci "name": "@ohos/moduel_a", 113e41f4b71Sopenharmony_ci "description": "module a", 114e41f4b71Sopenharmony_ci "version": "3.1", 115e41f4b71Sopenharmony_ci "license": "Apache License 2.0", 116e41f4b71Sopenharmony_ci "publishAs": "code-segment", 117e41f4b71Sopenharmony_ci "segment": { 118e41f4b71Sopenharmony_ci "destPath": "moduel_a_path" 119e41f4b71Sopenharmony_ci }, 120e41f4b71Sopenharmony_ci "dirs": {}, 121e41f4b71Sopenharmony_ci "scripts": {}, 122e41f4b71Sopenharmony_ci "component": { 123e41f4b71Sopenharmony_ci "name": "hisysevent_native", 124e41f4b71Sopenharmony_ci "subsystem": "hiviewdfx", 125e41f4b71Sopenharmony_ci "adapted_system_type": [ 126e41f4b71Sopenharmony_ci "standard" 127e41f4b71Sopenharmony_ci ], 128e41f4b71Sopenharmony_ci "rom": "", 129e41f4b71Sopenharmony_ci "ram": "", 130e41f4b71Sopenharmony_ci "hisysevent_config": [ 131e41f4b71Sopenharmony_ci "//moduel_a_path/yaml_file1.yaml", 132e41f4b71Sopenharmony_ci "//moduel_a_path/yaml_file2.yaml" 133e41f4b71Sopenharmony_ci ], 134e41f4b71Sopenharmony_ci "deps": { 135e41f4b71Sopenharmony_ci "components": [ 136e41f4b71Sopenharmony_ci "hilog_native", 137e41f4b71Sopenharmony_ci "hitrace_native", 138e41f4b71Sopenharmony_ci "ipc", 139e41f4b71Sopenharmony_ci "safwk", 140e41f4b71Sopenharmony_ci "samgr", 141e41f4b71Sopenharmony_ci "utils_base" 142e41f4b71Sopenharmony_ci ], 143e41f4b71Sopenharmony_ci "third_party": [] 144e41f4b71Sopenharmony_ci }, 145e41f4b71Sopenharmony_ci "build": { 146e41f4b71Sopenharmony_ci } 147e41f4b71Sopenharmony_ci } 148e41f4b71Sopenharmony_ci} 149e41f4b71Sopenharmony_ci``` 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci 152e41f4b71Sopenharmony_ci> **NOTE**<br> 153e41f4b71Sopenharmony_ci> The YAML file can be placed in any directory of the component project as needed. You only need to specify the path in the **bundle.json** file. 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci 156e41f4b71Sopenharmony_ci**Compiling YAML Files** 157e41f4b71Sopenharmony_ci 158e41f4b71Sopenharmony_ci- Perform full compilation. 159e41f4b71Sopenharmony_ci - During full compilation of the system, the configurations in the YAML files of all components are summarized. After the compilation is complete, the **hisysevent.zip** file will be generated in the specified directory. 160e41f4b71Sopenharmony_ci 161e41f4b71Sopenharmony_ci ``` 162e41f4b71Sopenharmony_ci cd *absolute path of the project's root directory* 163e41f4b71Sopenharmony_ci ./build --product-name <product name> 164e41f4b71Sopenharmony_ci ``` 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci - To obtain the **hisysevent.zip** file generated after full compilation, run the following commands: 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_ci ``` 169e41f4b71Sopenharmony_ci cd *absolute path of the project's root directory* 170e41f4b71Sopenharmony_ci find out -name hisysevent.zip -type f 171e41f4b71Sopenharmony_ci ``` 172e41f4b71Sopenharmony_ci 173e41f4b71Sopenharmony_ci- Single-file compilation: 174e41f4b71Sopenharmony_ci You can also compile the YAML file of a single component by running the following commands: 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci 177e41f4b71Sopenharmony_ci ``` 178e41f4b71Sopenharmony_ci cd absolute path of the project's root directory 179e41f4b71Sopenharmony_ci ./build/ohos/hisysevent/gen_def_from_all_yaml.py --yaml-list <yaml file list> --def-path <file store directory> 180e41f4b71Sopenharmony_ci ``` 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci **Table 3** Parameters for single-file compilation 183e41f4b71Sopenharmony_ci 184e41f4b71Sopenharmony_ci | Option| Description| 185e41f4b71Sopenharmony_ci | -------- | -------- | 186e41f4b71Sopenharmony_ci | --yaml-list | Paths of the YAML files to be compiled. If there are multiple YAML file paths, separate each of them with a space.| 187e41f4b71Sopenharmony_ci | --def-path | Path of the **hisysevent.zip** file generated after compilation.| 188e41f4b71Sopenharmony_ci 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci### Logging and Querying Events 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_ci1. Decompress the **hisysevent.zip** file to obtain the **hisysevent.def** file, and then use the [hdc_std tool](../subsystems/subsys-toolchain-hdc-guide.md) to push the file to the **/data/system/hiview/unzip_configs/sys_event_def/** directory of the device. 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ci2. Trigger logging of the custom system events in the YAML file. Then, run [hisysevent -l](../subsystems/subsys-dfx-hisysevent-tool.md) to query historical system events to find out if the logging of the custom system events is successful. 195