"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.debug = debug;
exports.error = error;
exports.event = event;
exports.fatal = fatal;
exports.getLatestLogFilePath = getLatestLogFilePath;
exports.info = info;
exports.prefixes = void 0;
exports.ready = ready;
exports.wait = wait;
exports.warn = warn;
var _path = require("path");
var _chalk = _interopRequireDefault(require("../compiled/chalk"));
var _fsExtra = _interopRequireDefault(require("../compiled/fs-extra"));
var _importLazy = require("./importLazy");
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
const enableFSLogger = process.env.FS_LOGGER !== 'none' && !process.versions.webcontainer;
const loggerDir = (0, _path.join)(process.cwd(), 'node_modules/.cache/logger');
const loggerPath = (0, _path.join)(loggerDir, 'umi.log');
const prefixes = {
  wait: _chalk.default.cyan('wait') + '  -',
  error: _chalk.default.red('error') + ' -',
  fatal: _chalk.default.red('fatal') + ' -',
  warn: _chalk.default.yellow('warn') + '  -',
  ready: _chalk.default.green('ready') + ' -',
  info: _chalk.default.cyan('info') + '  -',
  event: _chalk.default.magenta('event') + ' -',
  debug: _chalk.default.gray('debug') + ' -'
};
exports.prefixes = prefixes;
let logger;
if (enableFSLogger) {
  const {
    default: pino
  } = (0, _importLazy.importLazy)(require.resolve('pino'));
  _fsExtra.default.mkdirpSync(loggerDir);
  const customLevels = {
    ready: 31,
    event: 32,
    wait: 55,
    // 虽然这里设置了 debug 为 30，但日志中还是 20，符合预期
    // 这里不加会不生成到 umi.log，transport 的 level 配置没有生效，原因不明
    debug: 30
  };
  logger = pino({
    customLevels
  }, pino.transport({
    targets: [{
      target: require.resolve('pino/file'),
      options: {
        destination: loggerPath
      },
      level: 'trace'
    }]
  }));
} else {
  logger = {};
  Object.keys(prefixes).forEach(key => {
    logger[key] = () => {};
  });
}
function wait(...message) {
  console.log(prefixes.wait, ...message);
  logger.wait(message[0]);
}
function error(...message) {
  console.error(prefixes.error, ...message);
  logger.error(message[0]);
}
function warn(...message) {
  console.warn(prefixes.warn, ...message);
  logger.warn(message[0]);
}
function ready(...message) {
  console.log(prefixes.ready, ...message);
  logger.ready(message[0]);
}
function info(...message) {
  console.log(prefixes.info, ...message);
  logger.info(message[0]);
}
function event(...message) {
  console.log(prefixes.event, ...message);
  logger.event(message[0]);
}
function debug(...message) {
  if (process.env.DEBUG) {
    console.log(prefixes.debug, ...message);
  }
  logger.debug(message[0]);
}
function fatal(...message) {
  console.error(prefixes.fatal, ...message);
  logger.fatal(message[0]);
}
function getLatestLogFilePath() {
  return enableFSLogger ? loggerPath : null;
}