logs: when no timestamp, use the last known

This commit is contained in:
Girish Ramakrishnan
2024-10-14 16:27:06 +02:00
parent 1abbe43785
commit 23f9b5f2fc
+9 -2
View File
@@ -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 <ISOtimestamp> <msg>
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