Adding new logging function
This commit is contained in:
46
api/utils/helper.js
Normal file
46
api/utils/helper.js
Normal file
@@ -0,0 +1,46 @@
|
||||
export let setlvl = undefined;
|
||||
|
||||
export function setLevel(level){
|
||||
console.log(`Setting logging level to: ${level}`);
|
||||
setlvl = level;
|
||||
}
|
||||
|
||||
export function smartLogging(level, msg){
|
||||
if(setlvl == undefined){ //If no level is set treat it as console.log()
|
||||
console.log(msg);
|
||||
}else if(level <= setlvl){
|
||||
|
||||
switch (level) {
|
||||
case LoggingLevel.Error:
|
||||
console.error(msg);
|
||||
break;
|
||||
case LoggingLevel.Warning:
|
||||
console.warn(msg);
|
||||
break;
|
||||
case LoggingLevel.Logging:
|
||||
console.log(msg);
|
||||
break;
|
||||
case LoggingLevel.Debug:
|
||||
console.debug(msg);
|
||||
case LoggingLevel.AppTrace:
|
||||
console.debug(msg);
|
||||
break;
|
||||
case LoggingLevel.Trace:
|
||||
console.trace(msg);
|
||||
break;
|
||||
default:
|
||||
console.log(msg);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export const LoggingLevel = {
|
||||
Error: "10",
|
||||
Warning: "9",
|
||||
Logging: "8",
|
||||
Debug: "7",
|
||||
AppTrace: "6",
|
||||
Trace: "5"
|
||||
}
|
||||
Reference in New Issue
Block a user