import dayjs from 'dayjs';

export default class Logs {

  static out(...args) {
    const timeString = dayjs().format('YYYY-MM-DD HH:mm:ss.SSS');
    if (typeof args[0] === 'string' && args[0].includes('%')) {
      args[0] = `[${timeString}] ` + args[0];
    }
    else {
      args.unshift(`[${timeString}]`);
    }
    console.log(...args);
  }

  static err(...args) {
    const timeString = dayjs().format('YYYY-MM-DD HH:mm:ss.SSS');
    if (typeof args[0] === 'string' && args[0].includes('%')) {
      args[0] = `[${timeString}] ` + args[0];
    }
    else {
      args.unshift(`[${timeString}]`);
    }
    console.error(...args);
  }

  static outDev(...args) {
    if (process.env.NODE_ENV == 'development') {
      this.out(...args);
    }
  }

  static errDev(...args) {
    if (process.env.NODE_ENV == 'development') {
      this.err(...args);
    }
  }

  static outLine(string) {
    process.stdout.write("\u001b[1A");
    process.stdout.write("\u001b[2K");
    this.out(string);
  }

}