harmony 鸿蒙HiLog_Lite Development

  • 2022-08-09
  • 浏览 (621)

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);
        }
        ...
    }
    

你可能感兴趣的鸿蒙文章

harmony 鸿蒙Subsystems

harmony 鸿蒙AI Framework Development Guide

harmony 鸿蒙NNRt Access Adaptation

harmony 鸿蒙Application Privilege Configuration

harmony 鸿蒙Development Example

harmony 鸿蒙Setting Up a Development Environment

harmony 鸿蒙Development Guidelines

harmony 鸿蒙Application Framework Overview

harmony 鸿蒙ArkCompiler Development

harmony 鸿蒙Custom Window Title Bar Development

0  赞