[Feature][T108] [task-view-1792] Optimize the HAL log interface
Only Configure: No
Affected branch: GSW_V1453
Affected module: log
Self-test: yes
Doc Update: no
Change-Id: I6ad873a6c4351de9d1d7d6b09fec8ec9ce08841e
diff --git a/mbtk/libgsw_lib/gsw_log_interface.h b/mbtk/libgsw_lib/gsw_log_interface.h
new file mode 100755
index 0000000..98dc7b6
--- /dev/null
+++ b/mbtk/libgsw_lib/gsw_log_interface.h
@@ -0,0 +1,71 @@
+#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: [LOG_INIT_ERROR] [%s] " fmt, ptr_1001 + 1, line_1001, tag, ##args); \
+ }\
+ } while(0)
+
+#define _GET_MACRO(_1, _2, _3, NAME, ...) NAME
+
+#define LOGV(...) _GET_MACRO(__VA_ARGS__, LOGV_2, LOGV_1)(__VA_ARGS__)
+#define LOGV_1(fmt, args...) LOG(LOG_VERBOSE_LEVEL, "DEFAULT", fmt, ##args)
+#define LOGV_2(tag, fmt, args...) LOG(LOG_VERBOSE_LEVEL, tag, fmt, ##args)
+
+#define LOGI(...) _GET_MACRO(__VA_ARGS__, LOGI_2, LOGI_1)(__VA_ARGS__)
+#define LOGI_1(fmt, args...) LOG(LOG_INFO_LEVEL, "DEFAULT", fmt, ##args)
+#define LOGI_2(tag, fmt, args...) LOG(LOG_INFO_LEVEL, tag, fmt, ##args)
+
+#define LOGW(...) _GET_MACRO(__VA_ARGS__, LOGW_2, LOGW_1)(__VA_ARGS__)
+#define LOGW_1(fmt, args...) LOG(LOG_WARN_LEVEL, "DEFAULT", fmt, ##args)
+#define LOGW_2(tag, fmt, args...) LOG(LOG_WARN_LEVEL, tag, fmt, ##args)
+
+#define LOGE(...) _GET_MACRO(__VA_ARGS__, LOGE_2, LOGE_1)(__VA_ARGS__)
+#define LOGE_1(fmt, args...) LOG(LOG_ERR_LEVEL, "DEFAULT", fmt, ##args)
+#define LOGE_2(tag, fmt, args...) LOG(LOG_ERR_LEVEL, tag, fmt, ##args)
+
+#endif