From b325aa455521895d5950030795aab183f2047c71 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 13 Aug 2021 00:13:44 -0700 Subject: [PATCH] Fix log file writing --- native/jni/core/logging.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/native/jni/core/logging.cpp b/native/jni/core/logging.cpp index 46223cc18..9ed29de34 100644 --- a/native/jni/core/logging.cpp +++ b/native/jni/core/logging.cpp @@ -80,10 +80,6 @@ static void logfile_writer(int pipefd) { continue; } - // Read message - if (xread(pipefd, buf + TIME_FMT_LEN + 1, meta.len) != meta.len) - return; - timeval tv; tm tm; gettimeofday(&tv, nullptr); @@ -107,10 +103,14 @@ static void logfile_writer(int pipefd) { } size_t off = strftime(buf, sizeof(buf), "%m-%d %T", &tm); int ms = tv.tv_usec / 1000; - snprintf(buf + off, sizeof(buf) - off, + off += snprintf(buf + off, sizeof(buf) - off, ".%03d %5d %5d %c : ", ms, meta.pid, meta.tid, type); - strm->write(buf, TIME_FMT_LEN + meta.len); + // Read message + if (xread(pipefd, buf + off, meta.len) != meta.len) + return; + + strm->write(buf, off + meta.len); } }