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 9, 2024
1 parent ee52b1d commit e72e322
Showing 1 changed file with 16 additions and 30 deletions.
46 changes: 16 additions & 30 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ function App() {
{
query: {
type: "elasticsearch",
query_string: "application_name:gda",
query_string: "beamline:i15 AND application_name:gda",
},
timerange: {
from: 300,
Expand Down Expand Up @@ -181,8 +181,9 @@ function getMessage(logging: JSON): undefined | getMessageReturn {
);
host.push(logs[msg]["message"]["source"])
app_name.push(logs[msg]["message"]["application_name"]);
const text = logs[msg]["message"]["message"];
const [debug_level, log_message,level] = logLevel(text);
const level = logs[msg]["message"]["level"];
const log_message = logs[msg]["message"]["full_message"];
const debug_level = getLogLevel(level);
debug.push(debug_level);
message.push(log_message);
log_level.push(level);
Expand All @@ -195,33 +196,18 @@ 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,};
const words = text.split(/\s+/);
const firstWord = words[0] || '';
const restOfText = words.slice(2).join(' ');
let debug = "";
let message = "";
let level_val:number = 0;
if (firstWord in debug_levels) {
debug = firstWord;
message = restOfText;
level_val = debug_levels[firstWord];
} else {
debug = "UNKNOWN";
message = text;
level_val = 7;
}
return [debug, message, level_val];
function getLogLevel(level_val:number): string {
const log_levels: {[key: number]: string} = {
0:"EMERG",
1:"ALERT",
2:"CRIT",
3:"ERROR",
4:"WARN",
5:"NOTICE",
6:"INFO",
7:"DEBUG",};
let level = log_levels[level_val] || "UNKNOWN";

Check failure on line 209 in src/App.tsx

View workflow job for this annotation

GitHub Actions / build (18.x)

'level' is never reassigned. Use 'const' instead
return level;
}
async function readFile(): Promise<string> {
const filePath = "src/token.txt";
Expand Down

0 comments on commit e72e322

Please sign in to comment.