Skip to content

Commit 6e82d44

Browse files
committed
Added Columns to Table
1 parent 5767dbe commit 6e82d44

File tree

1 file changed

+56
-15
lines changed

1 file changed

+56
-15
lines changed

src/App.tsx

+56-15
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ import TableCell from '@mui/material/TableCell';
99
import TableContainer from '@mui/material/TableContainer';
1010
import TableRow from '@mui/material/TableRow';
1111
import Paper from '@mui/material/Paper';
12+
import { SpatialTracking } from "@mui/icons-material";
13+
import { TableHead } from "@mui/material";
1214

1315

1416
function App() {
15-
17+
const [time, setTime] = useState<string[]>([]);
18+
const [source, setSource] = useState<string[]>([]);
19+
const [debug, setDebug] = useState<string[]>([]);
1620
const [logs, setLogs] = useState<string[]>([]);
1721
useEffect(() => {
1822
async function fetchData(
@@ -44,7 +48,10 @@ function App() {
4448

4549
// Parsing the response as JSON
4650
const logdata = await response.json();
47-
const message = getMessage(logdata) || ["No logs found"];
51+
const [timestamp,source,debug,message] = getMessage(logdata) || ["No logs found"];
52+
setTime(timestamp);
53+
setSource(source);
54+
setDebug(debug);
4855
setLogs(message);
4956
} catch (error) {
5057
console.error("Error fetching data:", error);
@@ -119,46 +126,80 @@ function App() {
119126
<BoxBasic>
120127
<TableContainer component={Paper}>
121128
<Table sx={{ minWidth: 650 }} aria-label="simple table">
129+
<TableHead>
130+
<TableRow>
131+
<TableCell>Timestamp</TableCell>
132+
<TableCell>Debugging Level</TableCell>
133+
<TableCell>Source</TableCell>
134+
<TableCell>Log Messages</TableCell>
135+
</TableRow>
136+
</TableHead>
122137
<TableBody>
123-
{logs.map((log) => (
124-
<TableRow
125-
key={log}
126-
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
127-
>
128-
<TableCell component="th" scope="row">
129-
{log}
130-
</TableCell>
138+
{logs.map((log,index) => (
139+
<TableRow>
140+
<TableCell>{time[index]}</TableCell>
141+
<TableCell>{debug[index]}</TableCell>
142+
<TableCell>{source[index]}</TableCell>
143+
<TableCell>{log}</TableCell>
144+
{/* sx={{ '&:last-child td, &:last-child th': { border: 0 } }} */}
131145
</TableRow>
132146
))}
133-
</TableBody>
147+
</TableBody>
134148
</Table>
135149
</TableContainer>
136150
</BoxBasic>
137151
</ThemeProvider>
138152
);
139153
}
140154

141-
function getMessage(logging: JSON): undefined | string[] {
155+
function getMessage(logging: JSON): undefined | string[][] {
142156
const data = JSON.parse(JSON.stringify(logging));
143157
for (const key in data.results) {
144158
if ("search_types" in data.results[key]) {
145159
const id = data.results[key].search_types;
146160
const message: string[] = [];
161+
const timestamp: string[] =[];
162+
const source: string[] =[];
163+
const debug: string[] =[];
147164
for (const keys in id) {
148165
if ("messages" in id[keys]) {
149166
const logs = id[keys].messages;
167+
// populate different components of logged data and identifying log level
150168
for (const msg in logs) {
151-
message.push(
152-
`${logs[msg]["message"]["timestamp"]} ${logs[msg]["message"]["source"]} ${logs[msg]["message"]["message"]}`
169+
const formattedTimestamp = logs[msg]["message"]["timestamp"].replace(/[TZ]/g, ' ')
170+
timestamp.push(
171+
`${formattedTimestamp}`
153172
);
173+
source.push(
174+
`${logs[msg]["message"]["source"]}`
175+
)
176+
const text = logs[msg]["message"]["message"];
177+
const [debug_level, log_message] = debugLevel(text);
178+
debug.push(debug_level);
179+
message.push(log_message);
180+
154181
}
155-
return message;
182+
return [timestamp,source,debug,message];
156183
}
157184
}
158185
}
159186
}
160187
}
161188

189+
function debugLevel(text: string): [string, string] {
190+
const debug_levels = {"WARN":3,"INFO":1,"ERROR":4,"DEBUG":2}
191+
const words = text.split(/\s+/);
192+
const firstWord = words[0] || '';
193+
const restOfText = words.slice(2).join(' ');
194+
if (firstWord in debug_levels) {
195+
var debug = firstWord;
196+
var message = restOfText;
197+
} else {
198+
var debug = "UNKNOWN";
199+
var message = text;
200+
}
201+
return [debug, message];
202+
}
162203
async function readFile(): Promise<string> {
163204
const filePath = "src/token.txt";
164205
const response = await fetch(filePath) ;

0 commit comments

Comments
 (0)