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-02-07 01:22:54 +00:00
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
#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
|
|
|
};
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|