Add simple logger at the frontend
This commit is contained in:
parent
a0058eae63
commit
ff455414f8
1 changed files with 38 additions and 0 deletions
38
webapp/src/log.js
Normal file
38
webapp/src/log.js
Normal 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}`)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue