#define LOG_TAG "COREGL"
#include <dlog.h>
-unsigned int coregl_log_lvl;
-unsigned int coregl_dlog_enable;
-unsigned int coregl_log_initialized;
#define FONT_DEFAULT "\033[0m" /* for reset to default color */
#define FONT_RED "\033[31m" /* for error logs */
#define coregl_log_e(t, f, x...) \
do { \
- if(coregl_dlog_enable) \
+ if(coregl_get_dlog_enable()) \
LOGE(FONT_RED t " " f FONT_DEFAULT, ##x); \
else \
fprintf(stderr, FONT_RED t "[(pid:%d)(%s)] " f FONT_DEFAULT "\n", getpid(), __func__, ##x);\
#define coregl_log_w(t, f, x...) \
do { \
- if(coregl_dlog_enable) \
+ if(coregl_get_dlog_enable()) \
LOGW(FONT_YELLOW t " " f FONT_DEFAULT, ##x); \
else \
fprintf(stderr, FONT_YELLOW t "[(pid:%d)(%s)] " f FONT_DEFAULT "\n", getpid(), __func__, ##x);\
#define coregl_log_d(t, f, x...) \
do { \
- if(coregl_dlog_enable) \
+ if(coregl_get_dlog_enable()) \
LOGD(FONT_GREEN t " " f FONT_DEFAULT, ##x); \
else \
fprintf(stderr, FONT_GREEN t "[(pid:%d)(%s)] " f FONT_DEFAULT "\n", getpid(), __func__, ##x);\
#define LOG_INIT() \
do { \
- if (!coregl_log_initialized) { \
- char *lvl = (char *)getenv("COREGL_LOG_LEVEL"); \
- char *dlog = (char *)getenv("COREGL_TRACE_DLOG");\
- if (lvl) \
- coregl_log_lvl = atoi(lvl); \
+ if (!coregl_get_log_init()) { \
+ char *lvl = (char *)getenv("COREGL_LOG_LEVEL"); \
+ char *dlog = (char *)getenv("COREGL_TRACE_DLOG"); \
+ if (lvl) \
+ coregl_set_log_lvl(atoi(lvl)); \
else \
- coregl_log_lvl = _COREGL_DEFAULT_LOG_LEVEL;\
+ coregl_set_log_lvl(_COREGL_DEFAULT_LOG_LEVEL);\
\
if (dlog) \
- coregl_dlog_enable = atoi(dlog); \
+ coregl_set_dlog_enable(atoi(dlog)); \
else \
- coregl_dlog_enable = _COREGL_DLOG_ENABLE;\
- coregl_log_initialized = 1; \
+ coregl_set_dlog_enable(_COREGL_DLOG_ENABLE);\
+ coregl_set_log_init(1); \
} \
}while(0)
#define COREGL_ERR(f, x...) \
do { \
LOG_INIT(); \
- if(coregl_dlog_enable) \
+ if(coregl_get_dlog_enable()) \
coregl_log_e("[COREGL_ERROR]", f, ##x); \
else { \
- if (coregl_log_lvl > COREGL_LOG_INIT \
- && coregl_log_lvl <= COREGL_LOG_ERR) \
+ unsigned int lvl = coregl_get_log_lvl(); \
+ if (lvl > COREGL_LOG_INIT \
+ && lvl <= COREGL_LOG_ERR) \
coregl_log_e("[COREGL_ERROR]", f, ##x); \
} \
}while(0)
#define COREGL_WARN(f, x...) \
do { \
LOG_INIT(); \
- if(coregl_dlog_enable) \
+ if(coregl_get_dlog_enable()) \
coregl_log_w("[COREGL_WARN]", f, ##x); \
else { \
- if (coregl_log_lvl > COREGL_LOG_INIT \
- && coregl_log_lvl <= COREGL_LOG_WARN) \
+ unsigned int lvl = coregl_get_log_lvl(); \
+ if (lvl > COREGL_LOG_INIT \
+ && lvl <= COREGL_LOG_WARN) \
coregl_log_w("[COREGL_WARN]", f, ##x); \
} \
}while(0)
#define COREGL_DBG(f, x...) \
do { \
LOG_INIT(); \
- if(coregl_dlog_enable) \
+ if(coregl_get_dlog_enable()) \
coregl_log_d("[COREGL_DBG]", f, ##x); \
else{ \
- if (coregl_log_lvl > COREGL_LOG_INIT \
- && coregl_log_lvl <= COREGL_LOG_DBG) \
+ unsigned int lvl = coregl_get_log_lvl(); \
+ if (lvl > COREGL_LOG_INIT \
+ && lvl <= COREGL_LOG_DBG) \
coregl_log_d("[COREGL_DBG]", f, ##x); \
} \
}while(0)