Logger.js 651 Bytes
Newer Older
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
class Logger {

  constructor() {
    this.enabled = false;
  }

  enable() {
    this.enabled = true;
  }

  disable() {
    this.enabled = false;
  }

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

}

module.exports = new Logger();