blob: cc59c0feb82a0630a44dfd67b9203e218f736d69 [file] [log] [blame]
hj.shao57aca4a2025-07-17 22:52:58 -07001#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
29typedef void (*mbtk_log)(int level, const char *fmt, ...);
30
31extern mbtk_log gsw_fun_ptr_log;
32
33int init_log_func(void);
34
hj.shao0dc83de2025-07-18 02:52:44 -070035
hj.shao57aca4a2025-07-17 22:52:58 -070036#define LOG(level, tag, fmt, args...) \
hj.shao0dc83de2025-07-18 02:52:44 -070037 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.shao57aca4a2025-07-17 22:52:58 -070053
hj.shao57aca4a2025-07-17 22:52:58 -070054
hj.shao0dc83de2025-07-18 02:52:44 -070055#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.shao57aca4a2025-07-17 22:52:58 -070060
61#endif