1# HiLog\_Lite Development<a name="EN-US_TOPIC_0000001185815838"></a> 2 3## Overview<a name="section775017517390"></a> 4 5HiLog\_Lite is the HiLog framework for Mini-System Devices \(reference memory ≥ 128 KiB\) and Small-System Devices \(reference memory ≥ 1 MiB\). It implements functions such as log printing, log output, and flow control. 6 7## Available APIs<a name="section114412157402"></a> 8 9HiLog\_lite provides the following C APIs: 10 11``` 12HILOG_DEBUG(mod, fmt, ...) 13HILOG_INFO/HILOG_WARN/HILOG_ERROR/HILOG_FATAL 14``` 15 16**Table 1** Parameters of C APIs 17 18<a name="table998125624816"></a> 19<table><thead align="left"><tr id="row10981135611481"><th class="cellrowborder" valign="top" width="11.57%" id="mcps1.2.5.1.1"><p id="p11981145674811"><a name="p11981145674811"></a><a name="p11981145674811"></a>Parameter</p> 20</th> 21<th class="cellrowborder" valign="top" width="11.83%" id="mcps1.2.5.1.2"><p id="p39821456124810"><a name="p39821456124810"></a><a name="p39821456124810"></a>Mandatory?</p> 22</th> 23<th class="cellrowborder" valign="top" width="15.21%" id="mcps1.2.5.1.3"><p id="p139822056104811"><a name="p139822056104811"></a><a name="p139822056104811"></a>Data Type</p> 24</th> 25<th class="cellrowborder" valign="top" width="61.39%" id="mcps1.2.5.1.4"><p id="p3982145618482"><a name="p3982145618482"></a><a name="p3982145618482"></a>Description</p> 26</th> 27</tr> 28</thead> 29<tbody><tr id="row209821456144818"><td class="cellrowborder" valign="top" width="11.57%" headers="mcps1.2.5.1.1 "><p id="p20982125616483"><a name="p20982125616483"></a><a name="p20982125616483"></a>mod</p> 30</td> 31<td class="cellrowborder" valign="top" width="11.83%" headers="mcps1.2.5.1.2 "><p id="p1298245634810"><a name="p1298245634810"></a><a name="p1298245634810"></a>Yes</p> 32</td> 33<td class="cellrowborder" valign="top" width="15.21%" headers="mcps1.2.5.1.3 "><p id="p1198295634817"><a name="p1198295634817"></a><a name="p1198295634817"></a>uint8</p> 34</td> 35<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.2.5.1.4 "><p id="p0982145634817"><a name="p0982145634817"></a><a name="p0982145634817"></a>Indicates the module or service ID.</p> 36<p id="p1982155664820"><a name="p1982155664820"></a><a name="p1982155664820"></a>IDs are planned and assigned in a unified manner. A maximum of 64 IDs are supported. Third-party applications use <strong id="b14339112165018"><a name="b14339112165018"></a><a name="b14339112165018"></a>HILOG_MODULE_APP</strong> as their module ID.</p> 37</td> 38</tr> 39<tr id="row1898225611489"><td class="cellrowborder" valign="top" width="11.57%" headers="mcps1.2.5.1.1 "><p id="p9982656164812"><a name="p9982656164812"></a><a name="p9982656164812"></a>fmt</p> 40</td> 41<td class="cellrowborder" valign="top" width="11.83%" headers="mcps1.2.5.1.2 "><p id="p998255616484"><a name="p998255616484"></a><a name="p998255616484"></a>Yes</p> 42</td> 43<td class="cellrowborder" valign="top" width="15.21%" headers="mcps1.2.5.1.3 "><p id="p18982256194818"><a name="p18982256194818"></a><a name="p18982256194818"></a>char *</p> 44</td> 45<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.2.5.1.4 "><p id="p2982165664818"><a name="p2982165664818"></a><a name="p2982165664818"></a>Indicates the format specifier for output.</p> 46<a name="ol19982256164816"></a><a name="ol19982256164816"></a><ol id="ol19982256164816"><li>A maximum of six variable parameters are supported. <strong id="b774813235502"><a name="b774813235502"></a><a name="b774813235502"></a>%s</strong> is not supported.</li><li>The maximum length of a formatted log record is 128 bytes. If the maximum length is exceeded, the log cannot be printed.</li></ol> 47</td> 48</tr> 49<tr id="row16982105613488"><td class="cellrowborder" valign="top" width="11.57%" headers="mcps1.2.5.1.1 "><p id="p1898225604813"><a name="p1898225604813"></a><a name="p1898225604813"></a>Variable parameters</p> 50</td> 51<td class="cellrowborder" valign="top" width="11.83%" headers="mcps1.2.5.1.2 "><p id="p1698217568486"><a name="p1698217568486"></a><a name="p1698217568486"></a>No</p> 52</td> 53<td class="cellrowborder" valign="top" width="15.21%" headers="mcps1.2.5.1.3 "><p id="p189834566489"><a name="p189834566489"></a><a name="p189834566489"></a>int32</p> 54</td> 55<td class="cellrowborder" valign="top" width="61.39%" headers="mcps1.2.5.1.4 "><p id="p9983175654814"><a name="p9983175654814"></a><a name="p9983175654814"></a>Only numeric types are supported. A maximum of six variable parameters are allowed.</p> 56</td> 57</tr> 58</tbody> 59</table> 60 61## How to Develop<a name="section1482812550419"></a> 62 63The following provides an example of how the Samgr\_Lite module uses the HiLog\_Lite framework. 64 651. Add the module ID, and define **HILOG\_MODULE\_SAMGR** in the **HiLogModuleType** structure in **base/hiviewdfx/hilog\_lite/interfaces/native/kits/hilog\_lite/hiview\_log.h**. 66 67 ``` 68 typedef enum { 69 ... 70 HILOG_MODULE_SAMGR, 71 ... 72 } HiLogModuleType; 73 ``` 74 752. Register the module. Specifically, add the registration code to the **HiLogInit** function in **base/hiviewdfx/hilog\_lite/frameworks/mini/hiview\_log.c**. 76 77 ``` 78 HiLogRegisterModule(HILOG_MODULE_SAMGR, "SAMGR"); 79 ``` 80 813. Add the header file dependencies to the **foundation/systemabilitymgr/samgr\_lite/samgr/BUILD.gn** file. 82 83 ``` 84 include_dirs = [ 85 "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite", 86 ] 87 ``` 88 894. Reference the header file in the **foundation/systemabilitymgr/samgr\_lite/samgr/source/message.c** file and call the related APIs. 90 91 ``` 92 #include <log.h> 93 uint32 *SAMGR_SendSharedRequest(const Identity *identity, const Request *request, uint32 *token, Handler handler) 94 { 95 ... 96 if (err != EC_SUCCESS) { 97 HILOG_ERROR(HILOG_MODULE_SAMGR, "SharedSend [%p] failed(%d)!", identity->queueId, err); 98 (void)FreeReference(&exchange); 99 } 100 ... 101 } 102 ``` 103 104 105