console.log 带时间输出

适用于 nodejs 环境, 浏览器可以直接设置显示时间

{
    
    
  const newLog = function () {
    
    
    console.info(new Date().toLocaleString());
    arguments.callee.oLog.apply(this, arguments);
  };
  const newError = function () {
    
    
    console.info(new Date().toLocaleString());
    arguments.callee.oError.apply(this, arguments);
  };
  newLog.oLog = console.log;
  newError.oError = console.error;
  console.log = newLog;
  console.error = newError;
}

这样, console.logconsole.error 输出就可以附带时间了

2021/11/25 下午3:01:55
hello

猜你喜欢

转载自blog.csdn.net/MAIMIHO/article/details/121538712
今日推荐