Sfoglia il codice sorgente

update: 临时保存lib_log的修改

Wendal Chen 3 anni fa
parent
commit
1b5b244809
1 ha cambiato i file con 27 aggiunte e 9 eliminazioni
  1. 27 9
      luat/modules/luat_lib_log.c

+ 27 - 9
luat/modules/luat_lib_log.c

@@ -179,19 +179,24 @@ static int l_log_2_log(lua_State *L, const char* LEVEL) {
     {
         ntmp[0] = 0;
         len = 0;
-        switch(lua_type(L, i+1)) {
+        int index = i + 1;
+        switch(lua_type(L, index)) {
         case LUA_TNUMBER:
             if (lua_isinteger(L, i+1)) {
-                sprintf_(ntmp, "%lld", lua_tointeger(L, i+1));
+                #ifdef LUAT_USE_VM_64bit
+                sprintf_(ntmp, "%lld", lua_tointeger(L, index));
+                #else
+                sprintf_(ntmp, "%d", lua_tointeger(L, index));
+                #endif
             }
             else {
-                sprintf_(ntmp, "%.7g", lua_tonumber(L, i+1));
+                sprintf_(ntmp, "%.7g", lua_tonumber(L, index));
             }
             stmp = ntmp;
             len = strlen(ntmp);
             break;
         case LUA_TBOOLEAN :
-            if (lua_toboolean(L, i+1)) {
+            if (lua_toboolean(L, index)) {
                 stmp = STR_TURE;
             }
             else {
@@ -199,9 +204,20 @@ static int l_log_2_log(lua_State *L, const char* LEVEL) {
             }
             len = strlen(stmp);
             break;
+        case LUA_TNIL :
+            break;
+        case LUA_TFUNCTION:
+            if (lua_iscfunction(L, index)) {
+                sprintf_(ntmp, "function %p", lua_tocfunction(L, index));
+            }
+            else {
+                sprintf_(ntmp, "function %p", lua_topointer(L, index));
+            }
+            stmp = ntmp;
+            len = strlen(ntmp);
+            break;
         default:
-            stmp = lua_tolstring(L, i+1, &len);
-            LLOGD(">>? %s", stmp);
+            stmp = lua_tolstring(L, index, &len);
             break;
         }
         if (len == 0) {
@@ -211,16 +227,20 @@ static int l_log_2_log(lua_State *L, const char* LEVEL) {
         if (len + 1 > LOG_BUFF_LEN) {
             if (strlen(buff) > 0) {
                 luat_log_write(buff, strlen(buff));
+                luat_log_write("\n", 1);
                 buff[0] = 0;
             }
             luat_log_write(stmp, len);
+            luat_log_write("\n", 1);
         }
         else if (strlen(buff) + len + 2 > LOG_BUFF_LEN) {
             if (strlen(buff) > 0) {
                 luat_log_write(buff, strlen(buff));
                 buff[0] = 0;
+                luat_log_write("\n", 1);
             }
             memcpy(buff + strlen(buff), stmp, len);
+            len = 0;
         }
         else {
             buff[strlen(buff)] = '\t';
@@ -229,6 +249,7 @@ static int l_log_2_log(lua_State *L, const char* LEVEL) {
     }
     if (strlen(buff)) {
         luat_log_write(buff, strlen(buff));
+        luat_log_write("\n", 1);
     }
     return 0;
 }
@@ -244,9 +265,6 @@ static int l_log_2_log(lua_State *L, const char* LEVEL) {
 log.debug("onenet", "connect ok")
 */
 static int l_log_debug(lua_State *L) {
-    if (lua_isinteger(L, 2)) {
-        LLOGD(">>>>>>>>> %lld", luaL_checkinteger(L, 2));
-    }
     if (luat_log_get_level() > LUAT_LOG_DEBUG) return 0;
     return l_log_2_log(L, "D");
 }