2023-02-06 07:10:02 +00:00
|
|
|
//
|
|
|
|
// Created by xajhuang on 2023/2/6.
|
|
|
|
//
|
2023-02-20 02:59:47 +00:00
|
|
|
#include <string.h>
|
2023-02-06 07:10:02 +00:00
|
|
|
#include "zlog_module.h"
|
2023-03-17 07:42:15 +00:00
|
|
|
#include "common.h"
|
2023-03-03 07:17:20 +00:00
|
|
|
#include "config.h"
|
2023-02-07 01:22:54 +00:00
|
|
|
|
|
|
|
#define MAX_ZLOG_MOD_LEN (8)
|
2023-02-06 07:10:02 +00:00
|
|
|
|
|
|
|
typedef struct {
|
|
|
|
ZLOG_MOD_NAME logModule;
|
2023-02-20 02:59:47 +00:00
|
|
|
int minLevel;
|
2023-02-06 07:10:02 +00:00
|
|
|
zlog_category_t *pCat;
|
|
|
|
char catName[MAX_ZLOG_MOD_LEN];
|
2023-02-06 08:04:11 +00:00
|
|
|
} ZLOG_MODULE;
|
2023-02-06 07:10:02 +00:00
|
|
|
|
2023-02-20 02:59:47 +00:00
|
|
|
#define GENERATE_ENUM_ARRAY(ENUM, lv, desc) {ENUM, lv, NULL, desc},
|
2023-02-07 01:22:54 +00:00
|
|
|
|
2023-02-06 07:10:02 +00:00
|
|
|
static ZLOG_MODULE g_zlogModule[] = {
|
2023-02-20 02:59:47 +00:00
|
|
|
DEF_ZLOG_MOD(GENERATE_ENUM_ARRAY) {-1, ZLOG_LEVEL_FATAL, NULL, "UNKNOWN"}
|
2023-02-06 07:10:02 +00:00
|
|
|
};
|
|
|
|
|
2023-03-03 07:17:20 +00:00
|
|
|
#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
|
|
|
|
|
2023-02-06 07:10:02 +00:00
|
|
|
zlog_category_t *zlog_get_mod_cat(ZLOG_MOD_NAME logMod) {
|
2023-02-07 01:22:54 +00:00
|
|
|
if (logMod >= ARRAY_SIZE(g_zlogModule) || logMod < 0) {
|
|
|
|
logMod = ARRAY_SIZE(g_zlogModule) - 1;
|
2023-02-06 07:10:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (g_zlogModule[logMod].pCat == NULL) {
|
|
|
|
g_zlogModule[logMod].pCat = zlog_get_category(g_zlogModule[logMod].catName);
|
|
|
|
}
|
|
|
|
|
|
|
|
return g_zlogModule[logMod].pCat;
|
|
|
|
}
|
2023-02-20 02:59:47 +00:00
|
|
|
|
|
|
|
int zlog_verify_level(int level, ZLOG_MOD_NAME logMod) {
|
|
|
|
return (level >= g_zlogModule[logMod].minLevel);
|
|
|
|
}
|