egg icon indicating copy to clipboard operation
egg copied to clipboard

egg-logger 循环 reload

Open suntopo opened this issue 5 years ago • 2 comments

  _createStream() {
    mkdirp.sync(path.dirname(this.options.file));
    const stream = fs.createWriteStream(this.options.file, { flags: 'a' });

    const onError = err => {
      console.error('%s ERROR %s [egg-logger] [%s] %s',
        utility.logDate(','), process.pid, this.options.file, err.stack);
      this.reload(); // 又重新调用,导致不断循环
      console.warn('%s WARN %s [egg-logger] [%s] reloaded', utility.logDate(','), process.pid, this.options.file);
    };
    // only listen error once because stream will reload after error
    stream.once('error', onError);
    stream._onError = onError;
    return stream;
  }

通常情况下如果createWriteStream报错的话(权限,资源问题),一般是无法通过reload进行恢复的,而不断的reload不光不会修复问题,而且会消耗大量的硬件资源,不如抛个? @atian25

suntopo avatar Dec 02 '20 11:12 suntopo

?

suntopo avatar Feb 22 '21 07:02 suntopo

昨天同事又遇到这个问题了,看看这是个高频问题吗 ?@fengmk2

suntopo avatar Mar 20 '21 02:03 suntopo