summaryrefslogtreecommitdiff
path: root/protocols/Telegram/tdlib/td/example/web/tdweb/src/logger.js
blob: 95baed0318cfac7507c746a26812b0db11691391 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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, WARNING: 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;