vcpe/srcs/libs/include/zlog_module.h

102 lines
3.9 KiB
C
Raw Normal View History

2023-02-06 07:10:02 +00:00
//
// Created by xajhuang on 2023/2/6.
//
#ifndef VCPE_ZLOG_MODULE_H
#define VCPE_ZLOG_MODULE_H
#ifdef __cplusplus
extern "C" {
#endif
2023-03-31 06:32:32 +00:00
2023-02-06 07:10:02 +00:00
#include <zlog.h>
enum {
ZLOG_LEVEL_TRACE = 10,
};
typedef enum {
2023-03-31 06:32:32 +00:00
trace = ZLOG_LEVEL_TRACE,
debug = ZLOG_LEVEL_DEBUG,
info = ZLOG_LEVEL_INFO,
notice = ZLOG_LEVEL_NOTICE,
2023-03-31 06:32:32 +00:00
warn = ZLOG_LEVEL_WARN,
error = ZLOG_LEVEL_ERROR,
fatal = ZLOG_LEVEL_FATAL
} ZLOG_LV;
#define DEF_ZLOG_MOD(ZLOG_MOD) \
ZLOG_MOD(ZLOG_MOD_MAIN, ZLOG_LEVEL_DEBUG, "MAIN") \
ZLOG_MOD(ZLOG_MOD_TASK, ZLOG_LEVEL_DEBUG, "TASK") \
ZLOG_MOD(ZLOG_MOD_INIT, ZLOG_LEVEL_DEBUG, "INIT") \
ZLOG_MOD(ZLOG_MOD_MISC, ZLOG_LEVEL_DEBUG, "MISC") \
ZLOG_MOD(ZLOG_MOD_WATCH, ZLOG_LEVEL_DEBUG, "WATCH") \
ZLOG_MOD(ZLOG_MOD_CONFIG, ZLOG_LEVEL_DEBUG, "CONFIG") \
2023-03-31 06:32:32 +00:00
ZLOG_MOD(ZLOG_MOD_DB, ZLOG_LEVEL_DEBUG, "DB") \
ZLOG_MOD(ZLOG_MOD_NET, ZLOG_LEVEL_DEBUG, "NET") \
ZLOG_MOD(ZLOG_MOD_CRYPTO, ZLOG_LEVEL_DEBUG, "CRYPTO") \
ZLOG_MOD(ZLOG_MOD_MQ, ZLOG_LEVEL_DEBUG, "MQ") \
ZLOG_MOD(ZLOG_MOD_PROTO, ZLOG_LEVEL_DEBUG, "PROTO") \
ZLOG_MOD(ZLOG_MOD_HTTPD, ZLOG_LEVEL_INFO, "HTTPD") \
ZLOG_MOD(ZLOG_MOD_JSCHEM, ZLOG_LEVEL_INFO, "JSCHEM") \
ZLOG_MOD(ZLOG_MOD_USER, ZLOG_LEVEL_DEBUG, "USER") \
ZLOG_MOD(ZLOG_MOD_PPPOE, ZLOG_LEVEL_DEBUG, "PPPOE") \
ZLOG_MOD(ZLOG_MOD_VXLAN, ZLOG_LEVEL_DEBUG, "VXLAN") \
ZLOG_MOD(ZLOG_MOD_LWIP, ZLOG_LEVEL_DEBUG, "LWIP") \
ZLOG_MOD(ZLOG_MOD_DHCPD, ZLOG_LEVEL_DEBUG, "DHCPD") \
ZLOG_MOD(ZLOG_MOD_OPENDHCPD, ZLOG_LEVEL_DEBUG, "ODHCPD")
#define GENERATE_ZLOG_MOD_ENUM(ENUM, lv, x) ENUM,
2023-02-06 07:10:02 +00:00
typedef enum {
DEF_ZLOG_MOD(GENERATE_ZLOG_MOD_ENUM)
2023-02-06 07:10:02 +00:00
} ZLOG_MOD_NAME;
#define hzlog_trace(cat, buf, buf_len) \
hzlog(cat, __FILE__, sizeof(__FILE__) - 1, __func__, sizeof(__func__) - 1, __LINE__, ZLOG_LEVEL_DEBUG, buf, buf_len)
#define zlog_trace(cat, format, ...) \
zlog(cat, \
__FILE__, \
sizeof(__FILE__) - 1, \
__func__, \
sizeof(__func__) - 1, \
__LINE__, \
ZLOG_LEVEL_TRACE, \
format, \
##__VA_ARGS__)
2023-02-07 01:55:50 +00:00
#define LOG_MSG(level, format, ...) LOG_MOD(level, ZLOG_MOD_MAIN, format, ##__VA_ARGS__)
#define LOG_MSG_HEX(level, format, ...) LOG_MOD_HEX(level, ZLOG_MOD_MAIN, format, ##__VA_ARGS__)
#define LOG_MOD(level, mod, format, ...) \
do { \
if (zlog_verify_level(level, mod)) { \
if (zlog_vni_tag_get()) { \
zlog_put_mdc("vni", zlog_vni_tag_get()); \
} \
zlog_##level(zlog_get_mod_cat((mod)), format, ##__VA_ARGS__); \
} \
2023-02-06 07:10:02 +00:00
} while (0)
#define LOG_MOD_HEX(level, mod, format, ...) \
do { \
if (zlog_verify_level(level, mod)) { \
if (zlog_vni_tag_get()) { \
zlog_put_mdc("vni", zlog_vni_tag_get()); \
} \
hzlog_##level(zlog_get_mod_cat((mod)), format, ##__VA_ARGS__); \
2023-03-20 02:47:22 +00:00
printf("\n"); \
} \
2023-02-06 07:10:02 +00:00
} while (0)
zlog_category_t *zlog_get_mod_cat(ZLOG_MOD_NAME logMod);
2023-03-31 06:32:32 +00:00
int zlog_verify_level(int level, ZLOG_MOD_NAME logMod);
const char *zlog_vni_tag_get();
2023-02-06 07:10:02 +00:00
#ifdef __cplusplus
}
#endif
#endif //VCPE_ZLOG_MODULE_H