From 23f9b5f2fce027af04f17d1423a42a179002eb39 Mon Sep 17 00:00:00 2001 From: Girish Ramakrishnan Date: Mon, 14 Oct 2024 16:27:06 +0200 Subject: [PATCH] logs: when no timestamp, use the last known --- src/logs.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/logs.js b/src/logs.js index 342c5f1d4..da8b2e63b 100644 --- a/src/logs.js +++ b/src/logs.js @@ -16,6 +16,7 @@ class LogStream extends TransformStream { this._options = Object.assign({ source: 'unknown', format: 'json' }, options); this._decoder = new StringDecoder(); this._soFar = ''; + this._lastknownTimestamp = 0; } _format(line) { @@ -23,8 +24,14 @@ class LogStream extends TransformStream { const data = line.split(' '); // logs are let timestamp = (new Date(data[0])).getTime(); - if (isNaN(timestamp)) timestamp = 0; - const message = line.slice(data[0].length+1); + let message; + if (isNaN(timestamp)) { + timestamp = this._lastknownTimestamp; + message = line; + } else { + this._lastknownTimestamp = timestamp; + message = line.slice(data[0].length+1); + } return JSON.stringify({ realtimeTimestamp: timestamp * 1000, // timestamp info can be missing (0) for app logs via logPaths