Skip to content

Commit 0d1ea0a

Browse files
author
ymolodkov
committed
#126 Application Log available in UI
1 parent 2d9c48b commit 0d1ea0a

File tree

12 files changed

+148
-4
lines changed

12 files changed

+148
-4
lines changed

datanode-ui/public/translations/en/translation.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"users": "Users",
1010
"databases": "Databases",
1111
"envs": "Environments",
12-
"system_settings": "System Settings"
12+
"system_settings": "System Settings",
13+
"application_log": "Application log"
1314
},
1415
"pages": {
1516
"login": {
@@ -28,7 +29,8 @@
2829
"databases": "Databases",
2930
"users": "Users",
3031
"envs": "Environments",
31-
"system_settings": "System Settings"
32+
"system_settings": "System Settings",
33+
"application_log": "Application log"
3234
},
3335
"users": {
3436
"header": "Users",

datanode-ui/src/api/admin.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818
import { api } from ".";
19-
import { UserDTOSearchInterface } from "../libs/types";
19+
import {UserDTOInterface, UserDTOSearchInterface} from "../libs/types";
2020

2121
export const getUsers = (): Promise<UserDTOSearchInterface[]> =>
2222
api.get("/admin/admins");
@@ -34,3 +34,4 @@ export const systemSettings = (): Promise<any> => api.get("/admin/system-setting
3434

3535
export const updateSystemSettings = (value): Promise<any> => api.post("/admin/system-settings", value);
3636

37+
export const getApplicationLog = (): Promise<string> => api.get(`/application/logs/`);

datanode-ui/src/config.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -365,4 +365,8 @@ export const tabsAdmin = (t: any): TabsInterface[] => [
365365
value: "system-settings",
366366
title: t("pages.administration.tabs.system_settings"),
367367
},
368+
{
369+
value: "application-log",
370+
title: t("pages.administration.tabs.application_log"),
371+
}
368372
];

datanode-ui/src/libs/hooks/index.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,5 @@ export * from "./useList";
2323
export * from "./useModal";
2424
export * from "./useInterval";
2525
export * from "./useSystemSettings";
26-
export * from "./useSubmissionLog";
26+
export * from "./useSubmissionLog";
27+
export * from "./useApplicaionLog";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from "./useApplicationLog";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useState, useEffect } from 'react';
2+
import { getApplicationLog } from "../../../api/admin";
3+
import { useInterval } from '../useInterval';
4+
5+
export const useApplicationLog = () => {
6+
const [logs, setLogs] = useState<string>('');
7+
const [loading, setLoading] = useState<boolean>(true);
8+
const [error, setError] = useState<string | null>(null);
9+
10+
const fetchLogs = async () => {
11+
try {
12+
const response = await getApplicationLog();
13+
setLogs(response);
14+
setError(null);
15+
} catch (err) {
16+
setError('Error fetching logs');
17+
} finally {
18+
setLoading(false);
19+
}
20+
};
21+
22+
useInterval(() => {
23+
fetchLogs();
24+
// }, 10000);
25+
}, 10000);
26+
27+
useEffect(() => {
28+
fetchLogs();
29+
}, []);
30+
31+
return { logs, loading, error };
32+
};
33+

datanode-ui/src/modules/Admin/Admin.config.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export const tabsAdmin: TabsInterface[] = [
3030
value: "environments",
3131
title: "Enviroments",
3232
},
33+
{
34+
value: 'application-log',
35+
title: 'Application log',
36+
},
3337
{
3438
value: "system-settings",
3539
title: "System settings",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import React, {useEffect} from "react";
2+
import {Grid, Paper} from "@mui/material";
3+
import {useTranslation} from "react-i18next";
4+
import {CodeEditor} from "../../../libs/components";
5+
import {useDispatch} from "react-redux";
6+
import {setBreadcrumbs} from "../../../store/modules";
7+
import {useApplicationLog} from "../../../libs/hooks";
8+
9+
export const ApplicationLog: React.FC = () => {
10+
const {logs, loading, error} = useApplicationLog();
11+
const dispatch = useDispatch();
12+
const {t} = useTranslation();
13+
14+
useEffect(() => {
15+
dispatch(
16+
setBreadcrumbs([
17+
{
18+
name: t("breadcrumbs.admin"),
19+
path: "/administration",
20+
},
21+
{
22+
name: t("breadcrumbs.application_log"),
23+
path: "/application-log",
24+
},
25+
])
26+
);
27+
}, [dispatch, t]);
28+
29+
return (
30+
<Paper elevation={0} sx={{p: 2}}>
31+
{loading ? (
32+
<div>Loading...</div>
33+
) : error ? (
34+
<div>{error}</div>
35+
) : logs ? (
36+
<CodeEditor
37+
data={logs || ""}
38+
height={"73vh"}
39+
containerStyles={{padding: 0}}
40+
enableDownload={true}
41+
enableCopy
42+
readOnly
43+
consoleMode
44+
/>
45+
) : (
46+
<Grid item xs={12}>
47+
{/*<NoDataContainer>No available logs</NoDataContainer>*/}
48+
</Grid>
49+
)}
50+
</Paper>
51+
);
52+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
*
3+
* Copyright 2023 Odysseus Data Services, Inc.
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*
16+
*/
17+
18+
export * from "./ApplicationLog";

datanode-ui/src/modules/Admin/index.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { Databases } from "./Databases";
2929
import { Users } from "./Users";
3030
import { SystemSettings } from "./SystemSettings";
3131
import { EnviromentsList } from "./Enviroments";
32+
import { ApplicationLog } from "./ApplicationLog";
3233
import { tabsAdmin } from "../../config";
3334

3435
export const IndexAdmin: React.FC = () => {
@@ -66,6 +67,7 @@ export const IndexAdmin: React.FC = () => {
6667
<Route path="users/*" element={<Users />} />
6768
<Route path="environments/*" element={<EnviromentsList />} />
6869
<Route path="system-settings/*" element={<SystemSettings />} />
70+
<Route path="application-log/*" element={<ApplicationLog />} />
6971
</Routes>
7072
</Grid>
7173
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.odysseusinc.arachne.datanode.controller;
2+
3+
import org.springframework.beans.factory.annotation.Value;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.stereotype.Controller;
6+
import org.springframework.web.bind.annotation.RequestMapping;
7+
import org.springframework.web.bind.annotation.RequestMethod;
8+
9+
import java.io.IOException;
10+
import java.nio.file.Files;
11+
import java.nio.file.Paths;
12+
13+
@Controller
14+
public class LogController {
15+
16+
@Value("${logging.file.name}")
17+
private String logFilePath;
18+
19+
@RequestMapping(method = RequestMethod.GET, value = "/api/v1/application/logs/")
20+
public ResponseEntity<String> getLogs() throws IOException {
21+
String logs = new String(Files.readAllBytes(Paths.get(logFilePath)));
22+
return ResponseEntity.ok(logs);
23+
}
24+
}

datanode/src/main/resources/application.yml

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ security:
145145
validityInSeconds: ${datanode.jwt.expiration}
146146

147147
logging:
148+
file:
149+
name: logs/arachne.log
148150
level:
149151
root: INFO
150152
org.springframework.web.servlet.PageNotFound: ERROR

0 commit comments

Comments
 (0)