Skip to content

Commit

Permalink
lastest
Browse files Browse the repository at this point in the history
  • Loading branch information
HUAHUAI23 committed Jul 24, 2024
1 parent bc02a83 commit 1b177df
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions web/src/pages/app/mods/StatusBar/LogsModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ type Log = {

const MAX_RETRIES = 5;

const timestampRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z/;

function convertLogTimestamp(log: Log): Log {
const match = log.data.match(timestampRegex);

if (match) {
const timestamp = match[0];
const date = new Date(timestamp);
const clientTimeString = date.toString();
log.data = log.data.replace(timestamp, clientTimeString);
}

return log;
}

export default function LogsModal(props: { children: React.ReactElement }) {
const { children } = props;
const { isOpen, onOpen, onClose } = useDisclosure();
Expand Down Expand Up @@ -128,13 +143,14 @@ export default function LogsModal(props: { children: React.ReactElement }) {
}
},

onmessage(msg) {
onmessage(msg: Log) {
if (msg.event === "error") {
showWarning(msg.data);
}

if (msg.event === "log") {
addOrUpdateLog(msg);
const log: Log = convertLogTimestamp(msg);
addOrUpdateLog(log);
retryCountRef.current = 0;
}
},
Expand Down

0 comments on commit 1b177df

Please sign in to comment.