logs: when no timestamp, use the last known
This commit is contained in:
+9
-2
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user