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 May 6, 2024
1 parent 29269eb commit bc5a117
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 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] = getLogLevel(text,level);
debug.push(debug_level);
message.push(log_message);
log_level.push(level);
Expand All @@ -191,33 +192,29 @@ function getMessage(logging: JSON): undefined | getMessageReturn {
}
}

function logLevel(text: string): [string, string, number] {
const debug_levels: {[key: string]: number} = {
"EMERG":0,
"PANIC":0,
"ALERT":1,
"CRIT":2,
"ERROR":3,
"WARN":4,
"NOTICE":5,
"INFO":6,
"DEBUG":7,};
function getLogLevel(text: string, level_val:number): [string, string] {
const log_levels: {[key: number]: string} = {
0:"EMERG",
1:"ALERT",
2:"CRIT",
3:"ERROR",
4:"WARN",
5:"NOTICE",
6:"INFO",
7:"DEBUG",};
const words = text.split(/\s+/);
const firstWord = words[0] || '';
const restOfText = words.slice(2).join(' ');
let debug = "";
let level = "";
let message = "";
let level_val:number = 0;
if (firstWord in debug_levels) {
debug = firstWord;
if (Object.values(log_levels).includes(firstWord)) {
level = log_levels[level_val] || "UNKNOWN";
message = restOfText;
level_val = debug_levels[firstWord];
} else {
debug = "UNKNOWN";
level = "UNKNOWN";
message = text;
level_val = 7;
}
return [debug, message, level_val];
return [level, message];
}
async function readFile(): Promise<string> {
const filePath = "src/token.txt";
Expand Down

0 comments on commit bc5a117

Please sign in to comment.