Kaynağa Gözat

!2 fix log too long

chenliangyu 3 ay önce
ebeveyn
işleme
15a53fd04f

+ 11 - 4
Framework/libtoolkit/log.c

@@ -444,11 +444,18 @@ TOOLKIT_API int xlog_log_v(const char *inst, int level, const char *fmt, va_list
 		
 
 	n = _vscprintf(fmt, arg);//因为添加了Debug {}, 所以可能超过了1024长度
-	if (n >= 0 && n < 1050) {
-		char *buf = _alloca(n+1);
-		vsprintf(buf, fmt, arg);
+	if (n >= 0) {
+		int len = 1050 + 1;
+		char *buf = malloc(len);
+		if (buf) {
+			memset(buf, 0, len);
+			vsnprintf(buf, 1050, fmt, arg);
+			logfactory_log_record(log->factory, log, level, ft.dwLowDateTime, ft.dwHighDateTime, buf, strlen(buf));
+			free(buf);
+		}
+		
+		
 		
-		logfactory_log_record(log->factory, log, level, ft.dwLowDateTime, ft.dwHighDateTime, buf, n);
 		return 0;
 	}
 	return -1;

+ 13 - 0
Module/mod_guiconsole/mod_guiconsole.cpp

@@ -1062,6 +1062,19 @@ void CGUIConsoleSession::Handle_ReservedCall(SpReqAnsContext<GUIConsoleService_R
 		std::this_thread::sleep_for(std::chrono::seconds(10));
 		ctx->Answer(ErrorCodeEnum::Error_Succeed);
 	}
+	else if(ctx->Req.reqType == "test_longLog")
+	{
+		int srcLen = 2000;
+		int dstLen = 3000;
+		for(int i = srcLen; i < dstLen; i++)
+		{
+			CSimpleString len = CSimpleString::Format("%d,", i);
+			std::string src(i - len.GetLength(), 'a');
+			len += src.c_str();
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s", len);
+		}
+		ctx->Answer(ErrorCodeEnum::Error_Succeed);
+	}
 
 	
 }