Logger.js 682 Bytes
Newer Older
Alexander Bazo committed
1 2 3 4
/* eslint-disable no-console */

class Logger {

5 6 7
  constructor() {
    this.enabled = false;
  }
Alexander Bazo committed
8

9 10 11
  enable() {
    this.enabled = true;
  }
Alexander Bazo committed
12

13 14 15
  disable() {
    this.enabled = false;
  }
Alexander Bazo committed
16

17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
  log(msg, label) {
    let time = new Date(),
      hours = time.getUTCHours(),
      minutes = time.getUTCMinutes(),
      seconds = time.getUTCSeconds();
    if (hours < 10) {
      hours = "0" + hours;
    }
    if (minutes < 10) {
      minutes = "0" + minutes;
    }
    if (seconds < 10) {
      seconds = "0" + seconds;
    }
    if (this.enabled === false) {
      return;
    }
    console.log(`[${label}]\t${hours}:${minutes}:${seconds} - ${msg}`);
  }
Alexander Bazo committed
36 37 38 39

}

export default new Logger();