From 9e59a5cad96ea2bb7612e7a5adb7e85a2a0a0cf0 Mon Sep 17 00:00:00 2001 From: Thomas Thomas Date: Wed, 17 Apr 2024 14:26:15 +0100 Subject: [PATCH] Added Columns to Table --- src/App.tsx | 71 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 42518ab..a6c03b4 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -9,10 +9,14 @@ import TableCell from '@mui/material/TableCell'; import TableContainer from '@mui/material/TableContainer'; import TableRow from '@mui/material/TableRow'; import Paper from '@mui/material/Paper'; +import { SpatialTracking } from "@mui/icons-material"; +import { TableHead } from "@mui/material"; function App() { - + const [time, setTime] = useState([]); + const [source, setSource] = useState([]); + const [debug, setDebug] = useState([]); const [logs, setLogs] = useState([]); useEffect(() => { async function fetchData( @@ -44,7 +48,10 @@ function App() { // Parsing the response as JSON const logdata = await response.json(); - const message = getMessage(logdata) || ["No logs found"]; + const [timestamp,source,debug,message] = getMessage(logdata) || [["No logs found"]]; + setTime(timestamp); + setSource(source); + setDebug(debug); setLogs(message); } catch (error) { console.error("Error fetching data:", error); @@ -119,18 +126,25 @@ function App() { + + + Timestamp + Debugging Level + Source + Log Messages + + - {logs.map((log) => ( - - - {log} - + {logs.map((log,index) => ( + + {time[index]} + {debug[index]} + {source[index]} + {log} + {/* sx={{ '&:last-child td, &:last-child th': { border: 0 } }} */} ))} - +
@@ -138,27 +152,54 @@ function App() { ); } -function getMessage(logging: JSON): undefined | string[] { +function getMessage(logging: JSON): undefined | string[][] { const data = JSON.parse(JSON.stringify(logging)); for (const key in data.results) { if ("search_types" in data.results[key]) { const id = data.results[key].search_types; const message: string[] = []; + const timestamp: string[] =[]; + const source: string[] =[]; + const debug: string[] =[]; for (const keys in id) { if ("messages" in id[keys]) { const logs = id[keys].messages; + // populate different components of logged data and identifying log level for (const msg in logs) { - message.push( - `${logs[msg]["message"]["timestamp"]} ${logs[msg]["message"]["source"]} ${logs[msg]["message"]["message"]}` + const formattedTimestamp = logs[msg]["message"]["timestamp"].replace(/[TZ]/g, ' ') + timestamp.push( + `${formattedTimestamp}` ); + source.push( + `${logs[msg]["message"]["source"]}` + ) + const text = logs[msg]["message"]["message"]; + const [debug_level, log_message] = debugLevel(text); + debug.push(debug_level); + message.push(log_message); + } - return message; + return [timestamp,source,debug,message]; } } } } } +function debugLevel(text: string): [string, string] { + const debug_levels = {"WARN":3,"INFO":1,"ERROR":4,"DEBUG":2} + const words = text.split(/\s+/); + const firstWord = words[0] || ''; + const restOfText = words.slice(2).join(' '); + if (firstWord in debug_levels) { + var debug = firstWord; + var message = restOfText; + } else { + var debug = "UNKNOWN"; + var message = text; + } + return [debug, message]; +} async function readFile(): Promise { const filePath = "src/token.txt"; const response = await fetch(filePath) ;