diff --git a/crawler.js b/crawler.js index da3f7ca49..8ffb8a145 100644 --- a/crawler.js +++ b/crawler.js @@ -329,6 +329,8 @@ export class Crawler { await this.crawlState.setStatus(status); } + await this.closeLog(); + process.exit(exitCode); } } @@ -680,6 +682,7 @@ self.__bx_behaviors.selectMainBehavior(); async serializeAndExit() { await this.serializeConfig(); + await this.closeLog(); process.exit(0); } @@ -855,6 +858,19 @@ self.__bx_behaviors.selectMainBehavior(); } } + async closeLog() { + // close file-based log + logger.setExternalLogStream(null); + if (!this.logFH) { + return; + } + try { + await new Promise(resolve => this.logFH.close(() => resolve())); + } catch (e) { + // ignore + } + } + async generateWACZ() { logger.info("Generating WACZ"); await this.crawlState.setStatus("generate-wacz");