Add simple logger at the frontend

This commit is contained in:
Miguel de la Cruz 2021-09-15 22:52:53 +02:00
parent a0058eae63
commit ff455414f8

38
webapp/src/log.js Normal file
View file

@ -0,0 +1,38 @@
export const levelDebug = 0
export const levelInfo = 1
export const levelWarn = 2
export const levelError = 3
let level = levelDebug
export function setLogLevel(logLevel) {
level = logLevel
}
function nowStr() {
const now = new Date()
return `${now.getFullYear()}${now.getDate()}${now.getMonth()}.${now.getHours()}${now.getMinutes()}${now.getSeconds()}`
}
export function Debug(msg) {
if (level <= levelDebug) {
console.log(`[DBG ${nowStr()}] ${msg}`)
}
}
export function Info(msg) {
if (level <= levelInfo) {
console.log(`[INF ${nowStr()}] ${msg}`)
}
}
export function Warn(msg) {
if (level <= levelWarn) {
console.warn(`[WRN ${nowStr()}] ${msg}`)
}
}
export function Error(msg) {
if (level <= levelError) {
console.error(`[ERR ${nowStr()}] ${msg}`)
}
}