RDKEMW-22637 : [VIPA][NativeScript][Rogers] FW request is getting tru… - #137
RDKEMW-22637 : [VIPA][NativeScript][Rogers] FW request is getting tru…#137vjain008 wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses device log truncation for JavaScript console.* output by splitting long console messages into multiple log lines before sending them through the native logger.
Changes:
- Build the full console message once and emit it in chunks when it exceeds a maximum length.
- Prefix chunked log lines with a
[current/total]indicator to preserve ordering.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4d7395e to
7245a49
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Suppressed comments (3)
src/NativeJSLogger.cpp:96
- Even with the larger stack buffer, this path will still truncate any formatted log message longer than 2047 bytes (vsnprintf will cut it). Since the PR goal is to avoid truncation, consider sizing the buffer dynamically using a sizing vsnprintf with va_copy and then formatting into a heap buffer.
const char* levelStr = logLevelNames[level];
char buffer[2048];
vsnprintf(buffer, sizeof(buffer), format, args);
printf("\n[%s] JsRuntime Thread-%d: %s\n", levelStr, threadId, buffer);
src/jsc/JavaScriptUtils.cpp:884
oss.str()is materialized multiple times (once for the remote inspector and again forfullMsg). For long logs this adds avoidable copies; buildfullMsgonce and reuse it for both the inspector and NativeJSLogger.
const std::string fullMsg = oss.str();
constexpr size_t kMaxLogChunk = 2000;
src/jsc/JavaScriptUtils.cpp:895
- Splitting one logical console message into multiple log lines can interleave with other threads’ logs and make reconstruction hard. Adding an explicit part index to each chunk (and avoiding the non-ASCII continuation marker) makes logs easier to parse and reassemble reliably.
for (size_t start = 0; start < fullMsg.size(); start += kMaxLogChunk) {
const size_t len = std::min(kMaxLogChunk, fullMsg.size() - start);
std::string chunk(fullMsg.substr(start, len));
if (start + len < fullMsg.size()) {
chunk += " ↵";
7245a49 to
4d7395e
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/jsc/JavaScriptUtils.cpp:884
- The chunk size is set to 900 “to keep under device/syslog line limits”, but chunked log lines add a "[i/total] " prefix (and the logger may add its own prefix). As written, the emitted line length can exceed the intended limit and still truncate.
constexpr size_t kMaxLogChunk = 900; // keep under device/syslog line limits
src/jsc/JavaScriptUtils.cpp:883
- Line is indented with a tab, while surrounding code in this function uses spaces; this will likely fail style checks / create inconsistent formatting.
const std::string fullMsg = oss.str();
…ncated in device logs Reason for change: Logs are truncating Test Procedure: Full log line must display Risk: low Priority: P1
4d7395e to
fdff6e5
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/jsc/JavaScriptUtils.cpp:893
- The chunking loop can still produce lines longer than
kMaxLogChunkbecause the continuation marker is appended after slicing. If the device log truncation threshold is ~kMaxLogChunk, the marker can cause re-truncation. Also, chunking by byte length can split multi-byte UTF-8 sequences (console strings are UTF-8), which can produce invalid characters in logs.
size_t offset = 0;
while (offset < fullMsg.size()) {
const size_t len = std::min(kMaxLogChunk, fullMsg.size() - offset);
const bool hasMore = (offset + len) < fullMsg.size();
std::string chunk = fullMsg.substr(offset, len);
src/jsc/JavaScriptUtils.cpp:884
420is a magic number here; without context it's hard to know what log/truncation limit it corresponds to (NativeJSLogger has its own buffering and other log backends may add prefixes). Adding a short note about the source of this limit will make future adjustments safer.
This issue also appears on line 889 of the same file.
constexpr size_t kMaxLogChunk = 420;
…ncated in device logs
Reason for change: Logs are truncating
Test Procedure: Full log line must display
Risk: low
Priority: P1