我有一个使用 Winston 日志库的节点应用程序,它在 Winston 文件传输代码中调用 fs.stat 时失败。有问题的代码是(第 515-536 行的 file.js):
console.log("fullname = " + fullname);
fs.stat(fullname, function (err, stats) {
  console.log("CALLBACK");
  if (err) {
    if (err.code !== 'ENOENT') {
      return self.emit('error', err);
    }
    return createAndFlush(0);
  }
  if (!stats || (self.maxsize && stats.size >= self.maxsize)) {
    //
    // If `stats.size` is greater than the `maxsize` for
    // this instance then try again
    //
    return checkFile(self._getFile(true));
  }
  createAndFlush(stats.size);
});
我添加了 console.log 调用。第一个 on 打印在第一个日志事件中,但第二个永远不会到达。
该应用程序在 Windows 7 32 位的 Node.js 0.10.10 下运行。它适用于 Linux。应用程序的 http 服务器继续为事件提供服务,因此主事件循环正常。
以下简短应用程序对于存在的文件和不存在的文件正确运行:
fs = require('fs');
fs.stat('c:\\apiserver\\v8.log', function(err, st) {
    console.dir(err);
    console.dir(st);
});