mk_log_printf改用vasprintf函数

This commit is contained in:
ziyue 2021-10-18 15:09:02 +08:00
parent 74aa2ba07f
commit 5d9f05669e
2 changed files with 9 additions and 8 deletions

@ -1 +1 @@
Subproject commit ee7ae998aa5449a72ccb9615104b2198bc971a65 Subproject commit be74074d382a43e970de05fe88f412e5a05e38d6

View File

@ -11,6 +11,7 @@
#include "mk_util.h" #include "mk_util.h"
#include <stdarg.h> #include <stdarg.h>
#include <assert.h> #include <assert.h>
#include "Util/util.h"
#include "Util/logger.h" #include "Util/logger.h"
using namespace std; using namespace std;
using namespace toolkit; using namespace toolkit;
@ -47,12 +48,12 @@ API_EXPORT char* API_CALL mk_util_hex_dump(const void *buf, int len){
API_EXPORT void API_CALL mk_log_printf(int level, const char *file, const char *function, int line, const char *fmt, ...) { API_EXPORT void API_CALL mk_log_printf(int level, const char *file, const char *function, int line, const char *fmt, ...) {
assert(file && function && fmt); assert(file && function && fmt);
LogContextCapturer info(Logger::Instance(), (LogLevel) level, file, function, line); LogContextCapturer info(Logger::Instance(), (LogLevel) level, file, function, line);
va_list pArg; va_list ap;
va_start(pArg, fmt); va_start(ap, fmt);
char buf[4096]; char *str = nullptr;
auto n = vsnprintf(buf, sizeof(buf), fmt, pArg); vasprintf(&str, fmt, ap);
buf[n] = '\0'; va_end(ap);
va_end(pArg); info << str;
info << buf; free(str);
} }