Updated on 2022-03-13 GMT+08:00

Log API Usage

Defining the Log Module

  1. Define an ID for a log module. The value must be unique.

    #define USER_DEFINE_ERROR 0x6001

    The include/inc/hiaiengine/status.h file in the Atlas 500 DDK installation directory contains some module IDs. Ensure that new module IDs do not conflict with those defined in the file.

  2. Define the error code enumeration of the log module. If there are multiple errors, define multiple error codes in the enumeration.

    typedef enum 
    { 
    USER_DEFINE_OK_CODE, 
    USER_DEFINE_INVALID_CODE
    }
    USER_DEFINE_CODE;

  3. Register the error codes defined in 2 with HIAI_DEF_ERROR_CODE (macro definition). moduleId corresponds to the module ID defined in 1. loglevel is the log level registered for the error code. The value can be HIAI_ERROR, HIAI_INFO, HIAI_DEBUG, or HIAI_WARNING. codeName corresponds to the content of the enumeration ID (excluding _CODE) of the error code in 2. codeDesc indicates the error code description. The following describes the implementation of the macro definition and use sample:

    HIAI_DEF_ERROR_CODE(moduleId, logLevel, codeName, codeDesc)
    HIAI_DEF_ERROR_CODE(USER_DEFINE_ERROR,HIAI_ERROR,USER_DEFINE_OK,"OK")

Exporting Logs to the .dlog Log File

The Atlas 500 service software can call HIAI_ENGINE_LOG to output logs to the .dlog log file. For details, see "Logs (C++)" in the Matrix API Reference. There are eight log formats. This section describes one of them based on the log registration content. The definition and use sample are as follows:

  • The function format is as follows. For details about the parameters, see Table 1.
    #define HIAI_ENGINE_LOG(...) \ 
    HIAI_ENGINE_LOG_IMPL(__FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__) 
    void HIAI_ENGINE_LOG_IMPL(const char* funcPointer, const char* filePath, int lineNumber, const uint32_t  errorCode, const char* format, ...);
    Table 1 Parameter description

    Parameter

    Description

    errorCode

    Error code

    format

    Log description

    ...

    This is a variable parameter in the format and is added based on the log content.

  • HIAI_ENGINE_LOG is called as follows:
    HIAI_ENGINE_LOG(HIAI_INVALID_INPUT_MSG, "RUNNING OK");