@@ -9,10 +9,14 @@ import TableCell from '@mui/material/TableCell';
9
9
import TableContainer from '@mui/material/TableContainer' ;
10
10
import TableRow from '@mui/material/TableRow' ;
11
11
import Paper from '@mui/material/Paper' ;
12
+ import { SpatialTracking } from "@mui/icons-material" ;
13
+ import { TableHead } from "@mui/material" ;
12
14
13
15
14
16
function App ( ) {
15
-
17
+ const [ time , setTime ] = useState < string [ ] > ( [ ] ) ;
18
+ const [ source , setSource ] = useState < string [ ] > ( [ ] ) ;
19
+ const [ debug , setDebug ] = useState < string [ ] > ( [ ] ) ;
16
20
const [ logs , setLogs ] = useState < string [ ] > ( [ ] ) ;
17
21
useEffect ( ( ) => {
18
22
async function fetchData (
@@ -44,7 +48,10 @@ function App() {
44
48
45
49
// Parsing the response as JSON
46
50
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 ) ;
48
55
setLogs ( message ) ;
49
56
} catch ( error ) {
50
57
console . error ( "Error fetching data:" , error ) ;
@@ -119,46 +126,80 @@ function App() {
119
126
< BoxBasic >
120
127
< TableContainer component = { Paper } >
121
128
< 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 >
122
137
< 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 } }} */ }
131
145
</ TableRow >
132
146
) ) }
133
- </ TableBody >
147
+ </ TableBody >
134
148
</ Table >
135
149
</ TableContainer >
136
150
</ BoxBasic >
137
151
</ ThemeProvider >
138
152
) ;
139
153
}
140
154
141
- function getMessage ( logging : JSON ) : undefined | string [ ] {
155
+ function getMessage ( logging : JSON ) : undefined | string [ ] [ ] {
142
156
const data = JSON . parse ( JSON . stringify ( logging ) ) ;
143
157
for ( const key in data . results ) {
144
158
if ( "search_types" in data . results [ key ] ) {
145
159
const id = data . results [ key ] . search_types ;
146
160
const message : string [ ] = [ ] ;
161
+ const timestamp : string [ ] = [ ] ;
162
+ const source : string [ ] = [ ] ;
163
+ const debug : string [ ] = [ ] ;
147
164
for ( const keys in id ) {
148
165
if ( "messages" in id [ keys ] ) {
149
166
const logs = id [ keys ] . messages ;
167
+ // populate different components of logged data and identifying log level
150
168
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 ( / [ T Z ] / g, ' ' )
170
+ timestamp . push (
171
+ `${ formattedTimestamp } `
153
172
) ;
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
+
154
181
}
155
- return message ;
182
+ return [ timestamp , source , debug , message ] ;
156
183
}
157
184
}
158
185
}
159
186
}
160
187
}
161
188
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
+ }
162
203
async function readFile ( ) : Promise < string > {
163
204
const filePath = "src/token.txt" ;
164
205
const response = await fetch ( filePath ) ;
0 commit comments