1# HiSysEvent<a name="EN-US_TOPIC_0000001115694150"></a>
2
3-   [Introduction](#section11660541593)
4-   [Directory Structure](#section161941989596)
5-   [Description](#section1312121216216)
6    -   [Available APIs](#section1551164914237)
7    -   [Sample Code](#section129654513264)
8
9-   [Repositories Involved](#section1371113476307)
10
11## Introduction<a name="section11660541593"></a>
12
13HiSysEvent provides event logging APIs for OpenHarmony to record important information of key processes during system running, helping you locate faults. In addition, you can upload the log data to the cloud for big data analytics.
14
15**Figure  1**  HiSysEvent architecture<a name="fig1514425244110"></a>
16
17
18![](figures/en-us_image_0000001115534248.png)
19
20## Directory Structure<a name="section161941989596"></a>
21
22```
23/base/hiviewdfx/hisysevent   # HiSysEvent source code
24├── adapter                  # Platform adaptation code
25│  └── native               # native adaptation code
26├── frameworks               # Framework code
27│  └── native               # C/C++ APIs
28├── interfaces               # External APIs
29    └── native               # C++ APIs
30        └── innerkits        # C++ APIs opened to internal subsystems
31```
32
33## Description<a name="section1312121216216"></a>
34
35### Available APIs<a name="section1551164914237"></a>
36
37The following table lists the C++ APIs provided by the  **HiSysEvent**  class.
38
39**Table  1**  C++ APIs provided by HiSysEvent
40
41<a name="table1972602519328"></a>
42<table><thead align="left"><tr id="row5726112593219"><th class="cellrowborder" valign="top" width="57.38999999999999%" id="mcps1.2.3.1.1"><p id="p1472602523216"><a name="p1472602523216"></a><a name="p1472602523216"></a>API</p>
43</th>
44<th class="cellrowborder" valign="top" width="42.61%" id="mcps1.2.3.1.2"><p id="p12726112512322"><a name="p12726112512322"></a><a name="p12726112512322"></a>Description</p>
45</th>
46</tr>
47</thead>
48<tbody><tr id="row47261259328"><td class="cellrowborder" valign="top" width="57.38999999999999%" headers="mcps1.2.3.1.1 "><p id="p15726112583213"><a name="p15726112583213"></a><a name="p15726112583213"></a>template&lt;typename... Types&gt; static int Write(const std::string &amp;domain, const std::string &amp;eventName, EventType type, Types... keyValues)</p>
49</td>
50<td class="cellrowborder" valign="top" width="42.61%" headers="mcps1.2.3.1.2 "><p id="p14727325133216"><a name="p14727325133216"></a><a name="p14727325133216"></a>Logs system events.</p>
51<p id="p167271525203213"><a name="p167271525203213"></a><a name="p167271525203213"></a>Input parameters:</p>
52<a name="ul0727102516327"></a><a name="ul0727102516327"></a><ul id="ul0727102516327"><li><strong id="b2019634817576"><a name="b2019634817576"></a><a name="b2019634817576"></a>domain</strong>: Indicates the domain related to the event. You can use a preconfigured domain or customize a domain as needed. The name of a custom domain can contain a maximum of 16 characters, including digits (0-9), lowercase letters (a-z), uppercase letters (A-Z), and underscores (_). It must start with a letter.</li><li><strong id="b20954154912571"><a name="b20954154912571"></a><a name="b20954154912571"></a>eventName</strong>: Indicates the event name. The value contains a maximum of 32 characters, including digits (0 to 9), lowercase letters (a-z), uppercase letters (A-Z), and underscores (_). It must start with a letter.</li><li><strong id="b488285185718"><a name="b488285185718"></a><a name="b488285185718"></a>type</strong>: Indicates the event type. For details, see <strong id="b1667133015432"><a name="b1667133015432"></a><a name="b1667133015432"></a>EventType</strong>.</li><li><strong id="b19936135214571"><a name="b19936135214571"></a><a name="b19936135214571"></a>keyValues</strong>: Indicates the key-value pairs of event parameters. It can be in the format of the basic data type, <strong id="b79851431194316"><a name="b79851431194316"></a><a name="b79851431194316"></a>std::string</strong>, <strong id="b119861931204316"><a name="b119861931204316"></a><a name="b119861931204316"></a>std::vector<em id="i798503114317"><a name="i798503114317"></a><a name="i798503114317"></a>&lt;basic data type&gt;</em></strong>, or <strong id="b16986143164314"><a name="b16986143164314"></a><a name="b16986143164314"></a>std:vector&lt;std::string&gt;</strong>. The value contains a maximum of 48 characters, including digits (0 to 9), lowercase letters (a-z), uppercase letters (A-Z), and underscores (_). It must start with a letter. The number of parameters cannot exceed 128.</li></ul>
53<p id="p1727152513217"><a name="p1727152513217"></a><a name="p1727152513217"></a>Return value: If the operation is successful, <strong id="b277873515435"><a name="b277873515435"></a><a name="b277873515435"></a>0</strong> is returned. If the operation fails, a negative value is returned.</p>
54</td>
55</tr>
56</tbody>
57</table>
58
59### Sample Code<a name="section129654513264"></a>
60
61**C++**
62
631.  Develop the source code.
64
65    Include the  **HiSysEvent**  header file in the class definition header file or class implementation source file. For example:
66
67    ```
68    #include "hisysevent.h"
69    ```
70
71    Add the event logging code. For example, if you want to log events specific to the app start time \(start\_app\), then add the following code to the service implementation source file:
72
73    ```
74    HiSysEvent::Write(HiSysEvent::Domain::AAFWK, "start_app", HiSysEvent::EventType::BEHAVIOR, "app_name", "com.demo");
75    ```
76
772.  Configure compilation information. Specifically, add the subsystem SDK dependency to  **BUILD.gn**.
78
79    ```
80    external_deps = [ "hisysevent:libhisysevent" ]
81    ```
82
83
84## Repositories Involved<a name="section1371113476307"></a>
85
86[DFX subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/dfx.md)
87
88[hiviewdfx\_hiview](https://gitee.com/openharmony/hiviewdfx_hiview/blob/master/README.md)
89
90[hiviewdfx\_hilog](https://gitee.com/openharmony/hiviewdfx_hilog/blob/master/README.md)
91
92[hiviewdfx\_hiappevent](https://gitee.com/openharmony/hiviewdfx_hiappevent/blob/master/README.md)
93
94**hiviewdfx\_hisysevent**
95
96[hiviewdfx\_faultloggerd](https://gitee.com/openharmony/hiviewdfx_faultloggerd/blob/master/README.md)
97
98[hiviewdfx\_hilog\_lite](https://gitee.com/openharmony/hiviewdfx_hilog_lite/blob/master/README.md)
99
100[hiviewdfx\_hievent\_lite](https://gitee.com/openharmony/hiviewdfx_hievent_lite/blob/master/README.md)
101
102[hiviewdfx\_hiview\_lite](https://gitee.com/openharmony/hiviewdfx_hiview_lite/blob/master/README.md)
103
104