#ifndef GSW_LOG_INTERFACE_H | |
#define GSW_LOG_INTERFACE_H | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <unistd.h> | |
#include <fcntl.h> | |
#include <stdarg.h> | |
#include <dlfcn.h> | |
#include <syslog.h> | |
#ifndef LOG_ERR_LEVEL | |
#define LOG_ERR_LEVEL 3 /* error conditions */ | |
#endif | |
#ifndef LOG_WARN_LEVEL | |
#define LOG_WARN_LEVEL 4 /* warning conditions */ | |
#endif | |
#ifndef LOG_INFO_LEVEL | |
#define LOG_INFO_LEVEL 6 /* informational */ | |
#endif | |
#ifndef LOG_DEBUG_LEVEL | |
#define LOG_DEBUG_LEVEL 7 /* debug-level messages */ | |
#endif | |
#ifndef LOG_VERBOSE_LEVEL | |
#define LOG_VERBOSE_LEVEL 8 | |
#endif | |
typedef void (*mbtk_log)(int level, const char *fmt, ...); | |
extern mbtk_log gsw_fun_ptr_log; | |
int init_log_func(void); | |
#define LOG(level, tag, fmt, args...) \ | |
do { \ | |
char *file_ptr_1001 = __FILE__; \ | |
char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \ | |
char line_1001[10] = {0}; \ | |
sprintf(line_1001, "%d", __LINE__); \ | |
while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \ | |
if(*ptr_1001 == '/') \ | |
break; \ | |
ptr_1001--; \ | |
} \ | |
if(0 == init_log_func()) {\ | |
gsw_fun_ptr_log(level, "%s#%s: %s " fmt, ptr_1001 + 1, line_1001, tag, ##args); \ | |
} else { \ | |
printf("%s#%s: [%s] %s " fmt "\n", ptr_1001 + 1, line_1001, #level, tag, ##args); \ | |
} \ | |
} while(0) | |
#define LOGV(tag, fmt, args...) LOG(LOG_VERBOSE_LEVEL, tag, fmt, ##args) | |
#define LOGD(tag, fmt, args...) LOG(LOG_DEBUG_LEVEL, tag, fmt, ##args) | |
#define LOGI(tag, fmt, args...) LOG(LOG_INFO_LEVEL, tag, fmt, ##args) | |
#define LOGW(tag, fmt, args...) LOG(LOG_WARN_LEVEL, tag, fmt, ##args) | |
#define LOGE(tag, fmt, args...) LOG(LOG_ERR_LEVEL, tag, fmt, ##args) | |
#endif |