all files / lib/ log.js

72.97% Statements 27/37
62.5% Branches 10/16
75% Functions 6/8
60% Lines 15/25
4 statements, 1 branch Ignored     
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                                                           26× 26×           26× 26×        
import chalk from 'chalk';
import activity from 'activity-logger';
 
let verboseMode = false;
let isSilent = false;
 
export default {
  setLogLevel(logLevel) {
    if (logLevel === 'verbose') {
      verboseMode = true;
    }
  },
 
  setSilent(newSilent = false) {
    isSilent = newSilent;
  },
 
  info(...args) {
    const prefix = chalk.green('info') + ':\t';
    args.unshift(prefix);
    console.log.apply(console, args);
  },
 
  warn(...args) {
    Eif (!verboseMode) {
      return;
    }
    const prefix = chalk.yellow('warn') + ':\t';
    args.unshift(prefix);
    console.log.apply(console, args);
  },
 
  error(...args) {
    const prefix = chalk.red('error') + ':\t';
    args.unshift(prefix);
    console.log.apply(console, args);
  },
 
  startActivity(name) {
    Eif (isSilent) {
      return;
    }
    return activity.start(name);
  },
 
  endActivity(id) {
    Eif (isSilent) {
      return;
    }
    return activity.end(id);
  },
};