# HiSysEvent - [Introduction](#section11660541593) - [Directory Structure](#section161941989596) - [Description](#section1312121216216) - [Available APIs](#section1551164914237) - [Sample Code](#section129654513264) - [Repositories Involved](#section1371113476307) ## Introduction HiSysEvent 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. **Figure 1** HiSysEvent architecture ![](figures/en-us_image_0000001115534248.png) ## Directory Structure ``` /base/hiviewdfx/hisysevent # HiSysEvent source code ├── adapter # Platform adaptation code │ └── native # native adaptation code ├── frameworks # Framework code │ └── native # C/C++ APIs ├── interfaces # External APIs └── native # C++ APIs └── innerkits # C++ APIs opened to internal subsystems ``` ## Description ### Available APIs The following table lists the C++ APIs provided by the **HiSysEvent** class. **Table 1** C++ APIs provided by HiSysEvent

API

Description

template<typename... Types> static int Write(const std::string &domain, const std::string &eventName, EventType type, Types... keyValues)

Logs system events.

Input parameters:

  • domain: 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.
  • eventName: 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.
  • type: Indicates the event type. For details, see EventType.
  • keyValues: Indicates the key-value pairs of event parameters. It can be in the format of the basic data type, std::string, std::vector<basic data type>, or std:vector<std::string>. 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.

Return value: If the operation is successful, 0 is returned. If the operation fails, a negative value is returned.

### Sample Code **C++** 1. Develop the source code. Include the **HiSysEvent** header file in the class definition header file or class implementation source file. For example: ``` #include "hisysevent.h" ``` 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: ``` HiSysEvent::Write(HiSysEvent::Domain::AAFWK, "start_app", HiSysEvent::EventType::BEHAVIOR, "app_name", "com.demo"); ``` 2. Configure compilation information. Specifically, add the subsystem SDK dependency to **BUILD.gn**. ``` external_deps = [ "hisysevent:libhisysevent" ] ``` ## Repositories Involved [DFX subsystem](https://gitee.com/openharmony/docs/blob/master/en/readme/dfx.md) [hiviewdfx\_hiview](https://gitee.com/openharmony/hiviewdfx_hiview/blob/master/README.md) [hiviewdfx\_hilog](https://gitee.com/openharmony/hiviewdfx_hilog/blob/master/README.md) [hiviewdfx\_hiappevent](https://gitee.com/openharmony/hiviewdfx_hiappevent/blob/master/README.md) **hiviewdfx\_hisysevent** [hiviewdfx\_faultloggerd](https://gitee.com/openharmony/hiviewdfx_faultloggerd/blob/master/README.md) [hiviewdfx\_hilog\_lite](https://gitee.com/openharmony/hiviewdfx_hilog_lite/blob/master/README.md) [hiviewdfx\_hievent\_lite](https://gitee.com/openharmony/hiviewdfx_hievent_lite/blob/master/README.md) [hiviewdfx\_hiview\_lite](https://gitee.com/openharmony/hiviewdfx_hiview_lite/blob/master/README.md)