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 e068382 commit 687c74f
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,9 @@ function getMessage(logging: JSON): undefined | string[][] {
source.push(
`${logs[msg]["message"]["source"]}`
)
const level = logs[msg]["message"]["level"];
const text = logs[msg]["message"]["message"];
const [debug_level, log_message] = logLevel(text);
const [debug_level, log_message] = logLevel(text,level);
debug.push(debug_level);
message.push(log_message);

Expand All @@ -185,15 +186,23 @@ function getMessage(logging: JSON): undefined | string[][] {
}
}

function logLevel(text: string): [string, string] {
const debug_levels = {"INFO":1,"DEBUG":2,"WARN":3,"ERROR":4};
function logLevel(text: string, level_val:number): [string, string] {
const debug_levels: {[key: string]: number} = {
"EMERG":0,
"ALERT":1,
"CRIT":2,
"ERROR":3,
"WARN":4,
"NOTICE":5,
"INFO":6,
"DEBUG":7,};
const words = text.split(/\s+/);
const firstWord = words[0] || '';
const restOfText = words.slice(2).join(' ');
let debug = "";
let message = "";
if (firstWord in debug_levels) {
debug = firstWord;
debug = Object.keys(debug_levels).find(key => debug_levels[key] === level_val) || "UNKNOWN";
message = restOfText;
} else {
debug = "UNKNOWN";
Expand Down

0 comments on commit 687c74f

Please sign in to comment.