Kaynağa Gözat

add: 加个log的宏,方便dump数据到日志里分析

Wendal Chen 3 yıl önce
ebeveyn
işleme
21b49a1879
2 değiştirilmiş dosya ile 28 ekleme ve 0 silme
  1. 4 0
      luat/include/luat_log.h
  2. 24 0
      luat/modules/luat_lib_log.c

+ 4 - 0
luat/include/luat_log.h

@@ -43,6 +43,10 @@ void luat_log_log(int level, const char* tag, const char* _fmt, ...);
 #define luat_log_info(XTAG, format, ...)    luat_log_log(LUAT_LOG_INFO, XTAG, format, ##__VA_ARGS__)
 #define luat_log_debug(XTAG, format, ...)   luat_log_log(LUAT_LOG_DEBUG, XTAG, format, ##__VA_ARGS__)
 
+void luat_log_dump(const char* tag, void* ptr, size_t len);
+
+#define LLOGDUMP(ptr,len) luat_log_dump(LUAT_LOG_TAG, ptr, len)
+
 #endif
 
 #endif

+ 24 - 0
luat/modules/luat_lib_log.c

@@ -254,3 +254,27 @@ LUAMOD_API int luaopen_log( lua_State *L ) {
     luat_newlib2(L, reg_log);
     return 1;
 }
+
+void luat_log_dump(const char* tag, void* ptr, size_t len) {
+    if (ptr == NULL) {
+        luat_log_log(LUAT_LOG_DEBUG, tag, "ptr is NULL");
+        return;
+    }
+    if (len == 0) {
+        luat_log_log(LUAT_LOG_DEBUG, tag, "ptr len is 0");
+        return;
+    }
+    char buff[256] = {0};
+    char* ptr2 = ptr;
+    for (size_t i = 0; i < len; i++)
+    {
+        sprintf_(buff + strlen(buff), "%02X ", ptr2[i]);
+        if (i % 8 == 7) {
+            luat_log_log(LUAT_LOG_DEBUG, tag, "%s", buff);
+            buff[0] = 0;
+        }
+    }
+    if (strlen(buff)) {
+        luat_log_log(LUAT_LOG_DEBUG, tag, "%s", buff);
+    }
+}