1 Star 0 Fork 4.9K

丛林 / docs

forked from OpenHarmony / docs 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
subsys-dfx-hilog-lite.md 5.78 KB
一键复制 编辑 原始数据 按行查看 历史
huangxiaolinabc123 提交于 2022-08-15 14:36 . modify samgr

HiLog_Lite Development

Overview

HiLog_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.

Available APIs

HiLog_lite provides the following C APIs:

HILOG_DEBUG(mod, fmt, ...)
HILOG_INFO/HILOG_WARN/HILOG_ERROR/HILOG_FATAL

Table 1 Parameters of C APIs

Parameter

Mandatory?

Data Type

Description

mod

Yes

uint8

Indicates the module or service ID.

IDs are planned and assigned in a unified manner. A maximum of 64 IDs are supported. Third-party applications use HILOG_MODULE_APP as their module ID.

fmt

Yes

char *

Indicates the format specifier for output.

  1. A maximum of six variable parameters are supported. %s is not supported.
  2. The maximum length of a formatted log record is 128 bytes. If the maximum length is exceeded, the log cannot be printed.

Variable parameters

No

int32

Only numeric types are supported. A maximum of six variable parameters are allowed.

How to Develop

The following provides an example of how the Samgr_Lite module uses the HiLog_Lite framework.

  1. 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.

    typedef enum {
        ...
        HILOG_MODULE_SAMGR,
        ...
    } HiLogModuleType;
  2. Register the module. Specifically, add the registration code to the HiLogInit function in base/hiviewdfx/hilog_lite/frameworks/mini/hiview_log.c.

    HiLogRegisterModule(HILOG_MODULE_SAMGR, "SAMGR");
  3. Add the header file dependencies to the foundation/systemabilitymgr/samgr_lite/samgr/BUILD.gn file.

     include_dirs = [
          "//base/hiviewdfx/hilog_lite/interfaces/native/kits/hilog_lite",
     ]
  4. Reference the header file in the foundation/systemabilitymgr/samgr_lite/samgr/source/message.c file and call the related APIs.

    #include <log.h>
    uint32 *SAMGR_SendSharedRequest(const Identity *identity, const Request *request, uint32 *token, Handler handler)
    {
        ...
        if (err != EC_SUCCESS) {
            HILOG_ERROR(HILOG_MODULE_SAMGR, "SharedSend [%p] failed(%d)!", identity->queueId, err);
            (void)FreeReference(&exchange);
        }
        ...
    }
1
https://gitee.com/jungle8023/docs.git
git@gitee.com:jungle8023/docs.git
jungle8023
docs
docs
master

搜索帮助