在 winston 中将对象作为元数据传递时超出堆栈大小

stack size exceeded when passing objects as metadata in winston

在 ,winston 中,当我尝试通过将 mongoose 查询结果作为元数据参数传递来进行日志记录时,winston 在任务退出之前吐出了一千行日志。

所以对于这样的日志:

tSchool.findById(bus.schoolid,function(err,school){
   winston.info('loaded school',school);
});

这是一小部分得到的输出:

return _next.apply(this, arguments);
}, remove=function wrappedPointCut() {
  var args = [].slice.call(arguments);
  var lastArg = args.pop();
  var fn;
  var originalStack = new Error().stack;
  var $results;
  if (lastArg && typeof lastArg !== 'function') {
    args.push(lastArg);
  } else {
    fn = lastArg;
  }
  var promise = new Promise.ES6(function(resolve, reject) {
    args.push(function(error) {
      if (error) {
        // gh-2633: since VersionError is very generic, take the
        // stack trace of the original save() function call rather
        // than the async trace
        if (error instanceof VersionError) {
          error.stack = originalStack;
        }
        _this.$__handleReject(error);
        reject(error);
        return;
      }

      // There may be multiple results and promise libs other than
      // mpromise don't support passing multiple values to `resolve()`
      $results = Array.prototype.slice.call(arguments, 1);
      resolve.apply(promise, $results);
    });

    _this[newName].apply(_this, args);
  });
  if (fn) {
    if (_this.constructor.$wrapCallback) {
      fn = _this.constructor.$wrapCallback(fn);
    }
    return promise.then(
      function() {
        process.nextTick(function() {
          fn.apply(null, [null].concat($results));
        });
      },
      function(error) {
        process.nextTick(function() {
          fn(error);
        });
      });
  }
  return promise;
}

所以我想知道一些事情:

  1. 为什么传递一个 mongoose 查询结果,它应该只是一个小 json 对象,打印出这样的乱码?

  2. 其他对象是否也会发生这种情况 - 例如回调中的 err 对象等?

  3. 如何防止这种情况发生?检查每条日志语句以确保没有传递查询结果不是很实际。

提前致谢。

更新:

问题 #862, #474 and #914 是 tracking/related 这个问题,但一直没有太大进展。

此问题已在 Winston 的拉取请求 #977 中修复。你可以在公关页面查看详情。