vcpe/srcs/libs/zlog_module/zlog_module.c

55 lines
1.2 KiB
C

//
// Created by xajhuang on 2023/2/6.
//
#include <string.h>
#include "zlog_module.h"
#include "common.h"
#include "config.h"
#define MAX_ZLOG_MOD_LEN (8)
typedef struct {
ZLOG_MOD_NAME logModule;
int minLevel;
zlog_category_t *pCat;
char catName[MAX_ZLOG_MOD_LEN];
} ZLOG_MODULE;
#define GENERATE_ENUM_ARRAY(ENUM, lv, desc) {ENUM, lv, NULL, desc},
static ZLOG_MODULE g_zlogModule[] = {
DEF_ZLOG_MOD(GENERATE_ENUM_ARRAY) {-1, ZLOG_LEVEL_FATAL, NULL, "UNKNOWN"}
};
#ifdef USERVNI_ON
static char g_vni_str[64] = {0};
const char *zlog_vni_tag_get() {
if (strlen(g_vni_str) == 0) {
sprintf(g_vni_str, "%u", cfg_get_user_vni_id());
}
return (const char *)g_vni_str;
}
#else
const char *zlog_vni_tag_get() {
return "main";
}
#endif
zlog_category_t *zlog_get_mod_cat(ZLOG_MOD_NAME logMod) {
if (logMod >= ARRAY_SIZE(g_zlogModule) || logMod < 0) {
logMod = ARRAY_SIZE(g_zlogModule) - 1;
}
if (g_zlogModule[logMod].pCat == NULL) {
g_zlogModule[logMod].pCat = zlog_get_category(g_zlogModule[logMod].catName);
}
return g_zlogModule[logMod].pCat;
}
int zlog_verify_level(int level, ZLOG_MOD_NAME logMod) {
return (level >= g_zlogModule[logMod].minLevel);
}