昇腾社区首页
中文
注册

DlogRecordForC

函数原型

void DlogRecordForC(int moduleId, int level, const char *fmt, ...);

函数功能

打印日志(C接口)。

参数说明

参数

输入/输出

说明

module_id

输入

模块ID,具体请参见表1

level

输入

本条日志级别,具体请参见表1

fmt

输入

待打印的内容,具体请参见表1

返回值

无。

调用示例

char *msg= "hello";
DlogRecordForC(KERNEL | DEBUG_LOG_MASK, DLOG_INFO, "message is %s", msg);

宏定义及调用示例

头文件中还提供了相关宏,封装了DlogRecordForC供用户选择使用。

  • DlogForC
    //宏定义
    #define DlogForC(moduleId, level, fmt, ...)                                                 \
        do {                                                                                  \
            if (CheckLogLevelForC(moduleId, level) == 1) {                                           \
                DlogRecordForC(moduleId, level, "[%s:%d]" fmt, __FILE__, __LINE__, ##__VA_ARGS__);   \
            }                                                                                  \
        } while (TMP_LOG != 0)
    
    //调用示例
    char *msg= "hello";
    DlogForC(KERNEL | DEBUG_LOG_MASK, DLOG_INFO, "message is %s", msg);
  • DlogSubForC
    //宏定义
    #define DlogSubForC(moduleId, submodule, level, fmt, ...)                                                   \
        do {                                                                                                  \
            if (CheckLogLevelForC(moduleId, level) == 1) {                                                           \
                DlogRecordForC(moduleId, level, "[%s:%d][%s]" fmt, __FILE__, __LINE__, submodule, ##__VA_ARGS__);    \
            }                                                                                                   \
        } while (TMP_LOG != 0)
    
    //调用示例
    char *msg= "hello";
    DlogSubForC(KERNEL | DEBUG_LOG_MASK, "drv_log", DLOG_INFO, "message is %s", msg);