From ff455414f88c99f11e3729081d9bedcd53e5b7d8 Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Wed, 15 Sep 2021 22:52:53 +0200 Subject: [PATCH] Add simple logger at the frontend --- webapp/src/log.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 webapp/src/log.js diff --git a/webapp/src/log.js b/webapp/src/log.js new file mode 100644 index 0000000..a1ca099 --- /dev/null +++ b/webapp/src/log.js @@ -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}`) + } +}