This repository has been archived on 2020-05-25. You can view files and clone it, but cannot push or open issues or pull requests.
tdlib-fork/example/web/tdweb/src/logger.js
levlam d164512c4e Move Emscripten example to web directory.
GitOrigin-RevId: 2aebf9a549a32a3b06e82187e032d82e859bf4a0
2018-12-22 23:28:42 +03:00

48 lines
931 B
JavaScript

class Logger {
constructor() {
this.setVerbosity('WARNING');
}
debug(...str) {
if (this.checkVerbosity(4)) {
console.log(...str);
}
}
log(...str) {
if (this.checkVerbosity(4)) {
console.log(...str);
}
}
info(...str) {
if (this.checkVerbosity(3)) {
console.info(...str);
}
}
warn(...str) {
if (this.checkVerbosity(2)) {
console.warn(...str);
}
}
error(...str) {
if (this.checkVerbosity(1)) {
console.error(...str);
}
}
setVerbosity(level, default_level = 'info') {
if (level === undefined) {
level = default_level;
}
if (typeof level === 'string') {
level =
{ ERROR: 1, WARNINIG: 2, INFO: 3, LOG: 4, DEBUG: 4 }[
level.toUpperCase()
] || 2;
}
this.level = level;
}
checkVerbosity(level) {
return this.level >= level;
}
}
let log = new Logger();
export default log;