Skip to content

Commit

Permalink
Fix bug with container log formatting (rancher#9967)
Browse files Browse the repository at this point in the history
* Fix bug with container log formatting

* Fix lint issue
  • Loading branch information
nwmac authored Nov 3, 2023
1 parent 2437111 commit fdb061b
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions shell/components/nav/WindowManager/ContainerLogs.vue
Original file line number Diff line number Diff line change
Expand Up @@ -274,33 +274,36 @@ export default {
});
this.socket.addEventListener(EVENT_MESSAGE, (e) => {
const line = base64Decode(e.detail.data);
const data = base64Decode(e.detail.data);
let msg = line;
let time = null;
// Websocket message may contain multiple lines - loop through each line, one by one
data.split('\n').forEach((line) => {
let msg = line;
let time = null;
const idx = line.indexOf(' ');
const idx = line.indexOf(' ');
if ( idx > 0 ) {
const timeStr = line.substr(0, idx);
const date = new Date(timeStr);
if ( idx > 0 ) {
const timeStr = line.substr(0, idx);
const date = new Date(timeStr);
if ( !isNaN(date.getSeconds()) ) {
time = date.toISOString();
msg = line.substr(idx + 1);
if ( !isNaN(date.getSeconds()) ) {
time = date.toISOString();
msg = line.substr(idx + 1);
}
}
}
const parsedLine = {
id: lastId++,
msg: ansiup.ansi_to_html(msg),
rawMsg: msg,
time,
};
const parsedLine = {
id: lastId++,
msg: ansiup.ansi_to_html(msg),
rawMsg: msg,
time,
};
Object.freeze(parsedLine);
Object.freeze(parsedLine);
this.backlog.push(parsedLine);
this.backlog.push(parsedLine);
});
});
this.socket.connect();
Expand Down

0 comments on commit fdb061b

Please sign in to comment.