Skip to content

Commit c700ee4

Browse files
authored
fix luxon time parsing format to fix the invalid time in the logs screen (#2691)
1 parent 6557575 commit c700ee4

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

portal-ui/src/screens/Console/Logs/ErrorLogs/ErrorLogs.tsx

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import createStyles from "@mui/styles/createStyles";
2121
import withStyles from "@mui/styles/withStyles";
2222
import { useSelector } from "react-redux";
2323
import { FormControl, Grid, InputBase, MenuItem, Select } from "@mui/material";
24-
import { DateTime } from "luxon";
2524

2625
import { ErrorResponseHandler } from "../../../../../src/common/types";
2726
import api from "../../../../../src/common/api";
@@ -155,12 +154,6 @@ const ErrorLogs = () => {
155154
isValidEntry = false;
156155
}
157156

158-
const logTime = DateTime.fromFormat(
159-
m.time,
160-
"HH:mm:ss UTC MM/dd/yyyy"
161-
).toJSDate();
162-
163-
m.time = logTime;
164157
m.key = Math.random();
165158
if (userAgents.indexOf(m.userAgent) < 0 && m.userAgent !== undefined) {
166159
userAgents.push(m.userAgent);

portal-ui/src/screens/Console/Logs/ErrorLogs/LogLine.tsx

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { BoxArrowDown, BoxArrowUp, WarnFilledIcon } from "mds";
2525

2626
import getByKey from "lodash/get";
2727

28+
const timestampDisplayFmt = "HH:mm:ss ZZZZ MM/dd/yyyy"; //make this same as server logs format.
2829
const messageForConsoleMsg = (log: LogMessage) => {
2930
// regex for terminal colors like e.g. `[31;4m `
3031
const tColorRegex = /((\[[0-9;]+m))/g;
@@ -77,6 +78,13 @@ const messageForError = (log: LogMessage) => {
7778
return getByKey(log, keyPath, "");
7879
};
7980

81+
const logTime = DateTime.fromFormat(
82+
log.time.toString(),
83+
"HH:mm:ss z MM/dd/yyyy",
84+
{
85+
zone: "UTC",
86+
}
87+
);
8088
return (
8189
<Fragment>
8290
<div>
@@ -85,7 +93,7 @@ const messageForError = (log: LogMessage) => {
8593
</div>
8694
<div>
8795
<b style={labelStyle}>Time:&nbsp;</b>
88-
<span style={dataStyle}>{getLogEntryKey("time").toString()}</span>
96+
<span style={dataStyle}>{logTime.toFormat(timestampDisplayFmt)}</span>
8997
</div>
9098
<div>
9199
<b style={labelStyle}>DeploymentID:&nbsp;</b>
@@ -157,18 +165,23 @@ const LogLine = (props: { log: LogMessage }) => {
157165

158166
titleLogMessage = (titleLogMessage || "").replace(tColorRegex, "");
159167

160-
const logTime = DateTime.fromJSDate(log.time);
161-
162-
let dateStr = (
163-
<Fragment>{logTime.toFormat("yyyy/MM/dd HH:mm:ss (ZZZZ)")}</Fragment>
168+
const logTime = DateTime.fromFormat(
169+
log.time.toString(),
170+
"HH:mm:ss z MM/dd/yyyy",
171+
{
172+
zone: "UTC",
173+
}
164174
);
175+
const dateOfLine = logTime.toJSDate(); //DateTime.fromJSDate(log.time);
176+
177+
let dateStr = <Fragment>{logTime.toFormat(timestampDisplayFmt)}</Fragment>;
165178

166-
if (log.time.getFullYear() === 1) {
179+
if (dateOfLine.getFullYear() === 1) {
167180
dateStr = <Fragment>n/a</Fragment>;
168181
}
169182

170183
return (
171-
<React.Fragment key={log.time.toString()}>
184+
<React.Fragment key={logTime.toString()}>
172185
<TableRow
173186
sx={{
174187
"& > *": { borderBottom: "unset" },
@@ -180,17 +193,21 @@ const LogLine = (props: { log: LogMessage }) => {
180193
>
181194
<TableCell
182195
onClick={() => setOpen(!open)}
183-
style={{ width: 200, color: "#989898", fontSize: 12 }}
196+
style={{ width: 280, color: "#989898", fontSize: 12 }}
184197
>
185198
<Box
186199
sx={{
200+
display: "flex",
201+
gap: 1,
202+
alignItems: "center",
203+
187204
"& .min-icon": { width: 12, marginRight: 1 },
188205
fontWeight: "bold",
189206
lineHeight: 1,
190207
}}
191208
>
192209
<WarnFilledIcon />
193-
{dateStr}
210+
<div>{dateStr}</div>
194211
</Box>
195212
</TableCell>
196213
<TableCell

portal-ui/src/screens/Console/Logs/logsSlice.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
1818
import { LogMessage } from "./types";
19+
import { DateTime } from "luxon";
1920

2021
export interface LogState {
2122
logMessages: LogMessage[];
@@ -33,10 +34,17 @@ export const logsSlice = createSlice({
3334
reducers: {
3435
logMessageReceived: (state, action: PayloadAction<LogMessage>) => {
3536
let msgs = state.logMessages;
37+
const logTime = DateTime.fromFormat(
38+
action.payload.time.toString(),
39+
"HH:mm:ss z MM/dd/yyyy",
40+
{
41+
zone: "UTC",
42+
}
43+
).toJSDate();
3644

3745
if (
3846
msgs.length > 0 &&
39-
action.payload.time.getFullYear() === 1 &&
47+
logTime.getFullYear() === 1 &&
4048
action.payload.ConsoleMsg !== ""
4149
) {
4250
for (let m in msgs) {

0 commit comments

Comments
 (0)