暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. const chalk = require('chalk');
  2. LOG_TYPES = {
  3. NONE: 0,
  4. ERROR: 1,
  5. NORMAL: 2,
  6. DEBUG: 3,
  7. FFDEBUG: 4
  8. };
  9. let logType = LOG_TYPES.NORMAL;
  10. const setLogType = (type) => {
  11. if (typeof type !== 'number') return;
  12. logType = type;
  13. };
  14. const logTime = () => {
  15. let nowDate = new Date();
  16. return nowDate.toLocaleDateString() + ' ' + nowDate.toLocaleTimeString([], { hour12: false });
  17. };
  18. const log = (...args) => {
  19. if (logType < LOG_TYPES.NORMAL) return;
  20. console.log(logTime(), process.pid, chalk.bold.green('[INFO]'), ...args);
  21. };
  22. const error = (...args) => {
  23. if (logType < LOG_TYPES.ERROR) return;
  24. console.log(logTime(), process.pid, chalk.bold.red('[ERROR]'), ...args);
  25. };
  26. const debug = (...args) => {
  27. if (logType < LOG_TYPES.DEBUG) return;
  28. console.log(logTime(), process.pid, chalk.bold.blue('[DEBUG]'), ...args);
  29. };
  30. const ffdebug = (...args) => {
  31. if (logType < LOG_TYPES.FFDEBUG) return;
  32. console.log(logTime(), process.pid, chalk.bold.blue('[FFDEBUG]'), ...args);
  33. };
  34. module.exports = {
  35. LOG_TYPES,
  36. setLogType,
  37. log, error, debug, ffdebug
  38. }