subsys-dfx-hisysevent-logging-config.md 8.6 KB
Newer Older
S
shawn_he 已提交
1
# HiSysEvent Logging Configuration
S
shawn_he 已提交
2 3


S
shawn_he 已提交
4
## Overview
S
shawn_he 已提交
5

S
shawn_he 已提交
6 7 8

### Function Introduction

9
If 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 JSON file named **hisysevent.def**. After that, the compilation framework will put the JSON file to a specified path as the basis for the system to determine whether to log system events.
S
shawn_he 已提交
10 11 12


### Basic Concepts
S
shawn_he 已提交
13 14 15

Understanding the following concepts would be helpful for you in configuring HiSysEvent logging.

16
- 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.
S
shawn_he 已提交
17

18
- 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.
S
shawn_he 已提交
19

20
- 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.
S
shawn_he 已提交
21 22


S
shawn_he 已提交
23 24 25
### Constraints

Constraints on the event domain, event name, and parameter
S
shawn_he 已提交
26 27 28 29 30

- Each YAML file can contain only one event domain, and the domain name cannot be the same as that defined in other YAML files.

- Zero or more event names can be defined for one event domain. The event names in the same event domain must be unique.

S
shawn_he 已提交
31
- 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.
S
shawn_he 已提交
32 33 34 35
    **Table 1** Fields in the \__BASE parameter
  
  | Field| Description|
  | -------- | -------- |
S
shawn_he 已提交
36
  | type | Event type. This field is mandatory.<br>Value:<br>- **FAULT**: fault<br>- STATISTIC: statistics<br>- **SECURITY**: security<br>- **BEHAVIOR**: behavior|
S
shawn_he 已提交
37 38
  | level | Event level. This field is mandatory.<br>Value:<br>- CRITICAL: critical<br>- MINOR: minor|
  | 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.|
S
shawn_he 已提交
39 40
  | desc | Event name. This field is mandatory.<br>Rule:<br>-  A string of 3 to 128 characters.|
  | 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.|
S
shawn_he 已提交
41 42 43

    **Table 2** Description of custom parameters
  
S
shawn_he 已提交
44
  | Field| Description|
S
shawn_he 已提交
45 46 47
  | -------- | -------- |
  | 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 |
  | arrsize | Length of the parameter of the array type. This field is optional.<br>Value:<br>1-100|
S
shawn_he 已提交
48
  | desc | Parameter description. This field is mandatory.<br>Rule:<br>-  A string of 3 to 128 characters.|
S
shawn_he 已提交
49

S
shawn_he 已提交
50

51
## How to Develop
S
shawn_he 已提交
52

S
shawn_he 已提交
53

54
### Writing a YAML File
S
shawn_he 已提交
55 56


57
**Writing Rules**
S
shawn_he 已提交
58 59 60 61

- Event domain naming rules:
  - The name must start with a letter and can contain only uppercase letters, digits, and underscores (&#95;).
  - The name contains 1 to 16 characters.
S
shawn_he 已提交
62

S
shawn_he 已提交
63 64 65 66
- Event naming rules:
  - The name must start with a letter and can contain only uppercase letters, digits, and underscores (&#95;).
  - The name contains 1 to 32 characters.
  - The number of internal event names in an event domain cannot exceed 4096.
S
shawn_he 已提交
67

S
shawn_he 已提交
68 69
- Parameter naming rules:
  - The name must start with a letter and can contain only uppercase letters, digits, and underscores (&#95;).
X
xuyong 已提交
70
  - The name contains 1 to 48 characters.
S
shawn_he 已提交
71
  - The number of parameters in an event domain cannot exceed 128.
S
shawn_he 已提交
72 73


74
**Example**
S
shawn_he 已提交
75

S
shawn_he 已提交
76
- In the example YAML file, the event domain name is **MODULEA**. The event domain contains two events named **EVENT_NAMEA** and **EVENT_NAMEB**.
S
shawn_he 已提交
77

S
shawn_he 已提交
78
- **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**.
S
shawn_he 已提交
79

S
shawn_he 已提交
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
- **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.
  
  ```
  ##########################################
  # the hisysevent definition for module a #
  ##########################################
  
  domain: MODULEA
  
  EVENT_NAMEA:
      __BASE: {type: FAULT, level: CRITICAL, desc: event name a}
      NAME1: {type: STRING, desc: name1}
      NAME2: {type: STRING, desc: name2}
      NAME3: {type: UINT16, desc: name3}
  
  EVENT_NAMEB:
      __BASE: {type: STATISTIC, level: MINOR, tag: tag1 tag2, desc: event name b}
      NAME1: {type: UINT16, desc: name1}
      NAME2: {type: INT32, desc: name2}
  ```
S
shawn_he 已提交
100 101


102
### Verifying the YAML File
S
shawn_he 已提交
103 104


105
**Configuring the YAML File Path**
S
shawn_he 已提交
106 107

In the **bundle.json** file, use the **hisysevent_config** attribute to specify the YAML file path.
S
shawn_he 已提交
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139


```
{
    "name": "@ohos/moduel_a",
    "description": "module a",
    "version": "3.1",
    "license": "Apache License 2.0",
    "publishAs": "code-segment",
    "segment": {
        "destPath": "moduel_a_path"
    },
    "dirs": {},
    "scripts": {},
    "component": {
        "name": "hisysevent_native",
        "subsystem": "hiviewdfx",
        "adapted_system_type": [
            "standard"
        ],
        "rom": "",
        "ram": "",
        "hisysevent_config": [
            "//moduel_a_path/yaml_file1.yaml",
            "//moduel_a_path/yaml_file2.yaml"
        ],
        "deps": {
            "components": [
                "hilog_native",
                "hitrace_native",
                "ipc",
                "safwk",
H
huangxiaolinabc123 已提交
140
                "samgr",
S
shawn_he 已提交
141 142 143 144 145 146 147 148 149 150 151
                "utils_base"
            ],
            "third_party": []
        },
        "build": {
        }
    }
}
```


S
shawn_he 已提交
152 153
> **NOTE**<br>
> 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.
S
shawn_he 已提交
154 155


156
**Compiling YAML Files**
S
shawn_he 已提交
157

S
shawn_he 已提交
158 159 160 161 162 163 164
- Perform full compilation.
  - During full compilation of the system, the configurations in the YAML files of all components are summarized. After the compilation is complete, the **hisysevent.def** file will be generated in the specified directory.
    
     ```
     cd *absolute path of the project's root directory*
     ./build --product-name <product name>
     ```
S
shawn_he 已提交
165

S
shawn_he 已提交
166 167 168 169 170 171
  - To obtain the **hisysevent.def** file generated after full compilation, run the following commands:
    
     ```
     cd absolute path of the project's root directory
     find out -name hisysevent.def -type f
     ```
S
shawn_he 已提交
172

S
shawn_he 已提交
173 174
- Single-file compilation:
  You can also compile the YAML file of a single component by running the following commands:
S
shawn_he 已提交
175

S
shawn_he 已提交
176 177 178 179 180
  
  ```
  cd absolute path of the project's root directory
  ./build/ohos/hisysevent/gen_def_from_all_yaml.py --yaml-list <yaml file list> --def-path <file store directory>
  ```
S
shawn_he 已提交
181

S
shawn_he 已提交
182 183 184 185 186 187
    **Table 3** Parameters for single-file compilation
  
  | Option| Description|
  | -------- | -------- |
  | --yaml-list | Paths of the YAML files to be compiled. If there are multiple YAML file paths, separate each of them with a space.|
  | --def-path | Path of the **hisysevent.def** file generated after compilation.|
S
shawn_he 已提交
188 189


S
shawn_he 已提交
190
### Logging and Querying Events
S
shawn_he 已提交
191

S
shawn_he 已提交
192
1. Push the **hisysevent.def** file to the **/system/etc/hiview/** directory of the device by using the [hdc_std tool](../subsystems/subsys-toolchain-hdc-guide.md).
S
shawn_he 已提交
193

S
shawn_he 已提交
194
2. 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.