All files / utils logger.ts

57.14% Statements 20/35
16.66% Branches 1/6
20% Functions 1/5
57.14% Lines 20/35

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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 70 711x     1x   1x     1x       1x               1x           1x                     1x                     1x 7x         7x       1x 1x     1x 1x 1x 1x 1x 1x 1x    
import winston from 'winston';
import type { ProgressBar } from '../lib/progress';
 
let progressBar: ProgressBar | null = null;
 
const setProgressBar = (bar: ProgressBar) => {
  progressBar = bar;
};
const removeProgressBar = () => {
  progressBar = null;
};
 
const consoleTransport = new winston.transports.Console({
  colorize: true,
  handleExceptions: true,
  humanReadableUnhandledException: true,
  level: 'debug',
  showLevel: true,
});
 
winston.configure({
  exitOnError: false,
  transports: [consoleTransport],
});
 
// create a wrapper for error messages
const errorWrap = (input: any) => {
  if (progressBar) {
    progressBar.interruptBegin();
    winston.error(input);
    progressBar.interruptEnd();
  } else {
    winston.error(input);
  }
};
 
// create a wrapper for warning messages
const warnWrap = (input: any) => {
  if (progressBar) {
    progressBar.interruptBegin();
    winston.warn(input);
    progressBar.interruptEnd();
  } else {
    winston.warn(input);
  }
};
 
// create a wrapper for info messages
const infoWrap = (input: any) => {
  Iif (progressBar) {
    progressBar.interruptBegin();
    winston.info(input);
    progressBar.interruptEnd();
  } else {
    winston.info(input);
  }
};
 
const { debug } = winston;
const { verbose } = winston;
 
export {
  errorWrap as error,
  warnWrap as warn,
  infoWrap as info,
  verbose,
  debug,
  setProgressBar,
  removeProgressBar,
};