all files / src/__mocks__/ Logger.js

56.14% Statements 32/57
50% Branches 8/16
46.67% Functions 7/15
41.38% Lines 12/29
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69                                                                                                                  
/*eslint-disable */IIEE
let LOG_COUNT = 0;
 
const LOG_LEVEL = {
  log: 0,
  debug: 1,
  info: 2,
  success: 3,
  warning: 4,
  error: 5,
};
 
class Logger {
 
  constructor(name, level) {
    this.name = name;
    this.level = LOG_LEVEL[level] || LOG_LEVEL.log;
    this.printTrace = false;
    this.timers = {};
  }
 
  trace() {
    this.printTrace = true;
    return this;
  }
 
  log(level, message, data) {
    if(level >= this.level) {
      LOG_COUNT++;
      return this;
    }
  }
 
  debug(message, ...objs) {
    return this.log(LOG_LEVEL.debug, message, objs);
  }
 
  warning(message, ...objs) {
    return this.log(LOG_LEVEL.warning, message, objs);
  }
 
  info(message, ...objs) {
    return this.log(LOG_LEVEL.info, message, objs);
  }
 
  success(message, ...objs) {
    return this.log(LOG_LEVEL.success, message, objs);
  }
 
  error(message, ...objs) {
    return this.log(LOG_LEVEL.error, message, objs);
  }
 
  timer(name) {
    if (this.timers[name]) {
      delete timers[name];
    } else {
      this.timers[name] = true;
    }
  }
}
 
const getLogger = (context) => (new Logger(context));
 
export {
  Logger,
  getLogger,
};