Logger.js 722 Bytes
Newer Older
Alexander Bazo committed
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
/* eslint-env browser */
/* eslint-disable no-console */

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

}

let log = new Logger();
export default log;