Skip to content

Commit bed079c

Browse files
Adrinlolagneum
authored andcommitted
chore: Visual improvements to the log page in the DLE UI (#396):
* change `font-family` of logs-container inside the `Logs` tab to `Fira Code` * change error color inside the log-container to red. * limit log messages to 1000 and only render log messages that are not older than 20 minutes.
1 parent 1ca659c commit bed079c

File tree

4 files changed

+46
-12
lines changed

4 files changed

+46
-12
lines changed

ui/packages/ce/public/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@
1414
<!-- Google fonts: Mono -->
1515
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet">
1616

17+
<!-- Google fonts: Fira Code -->
18+
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@500&display=swap" rel="stylesheet">
19+
1720
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
1821
<meta name="theme-color" content="#000000">
1922
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">

ui/packages/platform/public/index.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<!-- Google fonts: Mono -->
2323
<link href="https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;1,100;1,200;1,300;1,400;1,500;1,600;1,700&display=swap" rel="stylesheet">
2424

25+
<!-- Google fonts: Fira Code -->
26+
<link href="https://fonts.googleapis.com/css2?family=Fira+Code:wght@500&display=swap" rel="stylesheet">
27+
2528
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
2629
<meta name="theme-color" content="#000000">
2730
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">

ui/packages/shared/pages/Instance/styles.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
padding: 0.5rem 1rem;
1515
& > p {
1616
font-size: medium;
17-
font-family: 'Source Code Pro, monospace';
17+
font-family: 'Fira Code', monospace;
18+
padding: 4px 0;
1819
}
1920
}
21+
22+
.error-log {
23+
color: red;
24+
}

ui/packages/shared/pages/Instance/wsLogs.ts

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1+
import moment from 'moment';
12
import { Api } from "./stores/Main";
23

34
const logsEndpoint = '/instance/logs';
45

6+
const LOGS_TIME_LIMIT = 20
7+
const LOGS_LINE_LIMIT = 1000
8+
59
export const establishConnection = async (api: Api) => {
610
const logElement = document.getElementById("logs-container");
711

@@ -10,13 +14,33 @@ export const establishConnection = async (api: Api) => {
1014
return;
1115
}
1216

13-
const appendLogElement = (logEntry: string) => {
14-
const tag = document.createElement("p");
15-
16-
tag.appendChild(document.createTextNode(logEntry));
17-
logElement.appendChild(tag);
18-
logElement.scrollIntoView(false);
19-
};
17+
const appendLogElement = (logEntry: string, logType?: string) => {
18+
const tag = document.createElement('p')
19+
tag.appendChild(document.createTextNode(logEntry))
20+
logElement.appendChild(tag)
21+
logElement.scrollIntoView(false)
22+
23+
if (logType === 'message') {
24+
const logEntryTime = moment.utc(
25+
logElement.children[0].innerHTML.split(' ').slice(0, 2).join(' '),
26+
)
27+
28+
const timeDifference =
29+
moment(logEntryTime).isValid() &&
30+
moment.duration(moment.utc(Date.now()).diff(logEntryTime)).asMinutes()
31+
32+
if (
33+
logElement.childElementCount > LOGS_LINE_LIMIT &&
34+
timeDifference > LOGS_TIME_LIMIT
35+
) {
36+
logElement.removeChild(logElement.children[0])
37+
}
38+
}
39+
40+
if (logEntry.split(' ')[3] === '[ERROR]') {
41+
tag.classList.add('error-log')
42+
}
43+
}
2044

2145
const { response, error } = await api.getWSToken({
2246
instanceId: "",
@@ -53,8 +77,7 @@ export const establishConnection = async (api: Api) => {
5377
};
5478

5579
socket.onmessage = function (event) {
56-
const logEntry = decodeURIComponent(atob(event.data));
57-
58-
appendLogElement(logEntry)
59-
};
80+
const logEntry = decodeURIComponent(atob(event.data))
81+
appendLogElement(logEntry, "message")
82+
}
6083
};

0 commit comments

Comments
 (0)