hj.shao | 57aca4a | 2025-07-17 22:52:58 -0700 | [diff] [blame] | 1 | #ifndef GSW_LOG_INTERFACE_H
|
| 2 | #define GSW_LOG_INTERFACE_H
|
| 3 |
|
| 4 | #include <stdio.h>
|
| 5 | #include <stdlib.h>
|
| 6 | #include <string.h>
|
| 7 | #include <unistd.h>
|
| 8 | #include <fcntl.h>
|
| 9 | #include <stdarg.h>
|
| 10 | #include <dlfcn.h>
|
| 11 | #include <syslog.h>
|
| 12 |
|
| 13 | #ifndef LOG_ERR_LEVEL
|
| 14 | #define LOG_ERR_LEVEL 3 /* error conditions */
|
| 15 | #endif
|
| 16 | #ifndef LOG_WARN_LEVEL
|
| 17 | #define LOG_WARN_LEVEL 4 /* warning conditions */
|
| 18 | #endif
|
| 19 | #ifndef LOG_INFO_LEVEL
|
| 20 | #define LOG_INFO_LEVEL 6 /* informational */
|
| 21 | #endif
|
| 22 | #ifndef LOG_DEBUG_LEVEL
|
| 23 | #define LOG_DEBUG_LEVEL 7 /* debug-level messages */
|
| 24 | #endif
|
| 25 | #ifndef LOG_VERBOSE_LEVEL
|
| 26 | #define LOG_VERBOSE_LEVEL 8
|
| 27 | #endif
|
| 28 |
|
| 29 | typedef void (*mbtk_log)(int level, const char *fmt, ...);
|
| 30 |
|
| 31 | extern mbtk_log gsw_fun_ptr_log;
|
| 32 |
|
| 33 | int init_log_func(void);
|
| 34 |
|
hj.shao | 0dc83de | 2025-07-18 02:52:44 -0700 | [diff] [blame] | 35 |
|
hj.shao | 57aca4a | 2025-07-17 22:52:58 -0700 | [diff] [blame] | 36 | #define LOG(level, tag, fmt, args...) \
|
hj.shao | 0dc83de | 2025-07-18 02:52:44 -0700 | [diff] [blame] | 37 | do { \
|
| 38 | char *file_ptr_1001 = __FILE__; \
|
| 39 | char *ptr_1001 = file_ptr_1001 + strlen(file_ptr_1001) - 1; \
|
| 40 | char line_1001[10] = {0}; \
|
| 41 | sprintf(line_1001, "%d", __LINE__); \
|
| 42 | while(ptr_1001 >= file_ptr_1001 && *ptr_1001){ \
|
| 43 | if(*ptr_1001 == '/') \
|
| 44 | break; \
|
| 45 | ptr_1001--; \
|
| 46 | } \
|
| 47 | if(0 == init_log_func()) {\
|
| 48 | gsw_fun_ptr_log(level, "%s#%s: %s " fmt, ptr_1001 + 1, line_1001, tag, ##args); \
|
| 49 | } else { \
|
| 50 | printf("%s#%s: [%s] %s " fmt "\n", ptr_1001 + 1, line_1001, #level, tag, ##args); \
|
| 51 | } \
|
| 52 | } while(0)
|
hj.shao | 57aca4a | 2025-07-17 22:52:58 -0700 | [diff] [blame] | 53 |
|
hj.shao | 57aca4a | 2025-07-17 22:52:58 -0700 | [diff] [blame] | 54 |
|
hj.shao | 0dc83de | 2025-07-18 02:52:44 -0700 | [diff] [blame] | 55 | #define LOGV(tag, fmt, args...) LOG(LOG_VERBOSE_LEVEL, tag, fmt, ##args)
|
| 56 | #define LOGD(tag, fmt, args...) LOG(LOG_DEBUG_LEVEL, tag, fmt, ##args)
|
| 57 | #define LOGI(tag, fmt, args...) LOG(LOG_INFO_LEVEL, tag, fmt, ##args)
|
| 58 | #define LOGW(tag, fmt, args...) LOG(LOG_WARN_LEVEL, tag, fmt, ##args)
|
| 59 | #define LOGE(tag, fmt, args...) LOG(LOG_ERR_LEVEL, tag, fmt, ##args)
|
hj.shao | 57aca4a | 2025-07-17 22:52:58 -0700 | [diff] [blame] | 60 |
|
| 61 | #endif
|