Skip to content

Commit

Permalink
Added Log Levels according to API Response
Browse files Browse the repository at this point in the history
  • Loading branch information
TBThomas56 committed Apr 30, 2024
1 parent 29269eb commit 0bb7a84
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,9 @@ function getMessage(logging: JSON): undefined | getMessageReturn {
source.push(
`${logs[msg]["message"]["source"]}`
)
const level = logs[msg]["message"]["level"];
const text = logs[msg]["message"]["message"];
const [debug_level, log_message,level] = logLevel(text);
const [debug_level, log_message] = logLevel(text,level);
debug.push(debug_level);
message.push(log_message);
log_level.push(level);
Expand All @@ -191,10 +192,9 @@ function getMessage(logging: JSON): undefined | getMessageReturn {
}
}

function logLevel(text: string): [string, string, number] {
function logLevel(text: string, level_val:number): [string, string] {
const debug_levels: {[key: string]: number} = {
"EMERG":0,
"PANIC":0,
"ALERT":1,
"CRIT":2,
"ERROR":3,
Expand All @@ -207,17 +207,14 @@ function logLevel(text: string): [string, string, number] {
const restOfText = words.slice(2).join(' ');
let debug = "";
let message = "";
let level_val:number = 0;
if (firstWord in debug_levels) {
debug = firstWord;
debug = Object.keys(debug_levels).find(key => debug_levels[key] === level_val) || "UNKNOWN";
message = restOfText;
level_val = debug_levels[firstWord];
} else {
debug = "UNKNOWN";
message = text;
level_val = 7;
}
return [debug, message, level_val];
return [debug, message];
}
async function readFile(): Promise<string> {
const filePath = "src/token.txt";
Expand Down

0 comments on commit 0bb7a84

Please sign in to comment.