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}`) + } +}