From 7e264657fd6c263d791966e4844674d951e66713 Mon Sep 17 00:00:00 2001 From: Romain Lenzotti Date: Sat, 2 Sep 2023 14:01:43 +0200 Subject: [PATCH] fix(di): fix issue when pushing logs after request end (#2423) --- packages/di/jest.config.js | 4 ++-- packages/di/src/node/domain/ContextLogger.ts | 6 +++++- packages/di/src/node/domain/DIContext.ts | 2 +- .../src/middlewares/PlatformLogMiddleware.ts | 2 -- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/packages/di/jest.config.js b/packages/di/jest.config.js index 256b156e67f..380d5bf507e 100644 --- a/packages/di/jest.config.js +++ b/packages/di/jest.config.js @@ -6,9 +6,9 @@ module.exports = { coverageThreshold: { global: { statements: 98.81, - branches: 96.54, + branches: 96.55, lines: 98.81, - functions: 98.32 + functions: 98.34 } } }; diff --git a/packages/di/src/node/domain/ContextLogger.ts b/packages/di/src/node/domain/ContextLogger.ts index b728d3fdba4..2cadc65fc17 100644 --- a/packages/di/src/node/domain/ContextLogger.ts +++ b/packages/di/src/node/domain/ContextLogger.ts @@ -79,7 +79,7 @@ export class ContextLogger { return this; } - public flush() { + public flush(stream = false) { if (this.stack.length) { this.stack.forEach(({level, data}: any) => { this.#logger[level](data); @@ -87,6 +87,10 @@ export class ContextLogger { this.#stack = []; } + + if (stream) { + this.maxStackSize = 0; + } } public isLevelEnabled(otherLevel: string | LogLevel) { diff --git a/packages/di/src/node/domain/DIContext.ts b/packages/di/src/node/domain/DIContext.ts index 749dcbe31da..dc326991665 100644 --- a/packages/di/src/node/domain/DIContext.ts +++ b/packages/di/src/node/domain/DIContext.ts @@ -73,7 +73,7 @@ export class DIContext { } destroy(): Promise { - return Promise.all([this.#container?.destroy(), this.#logger?.flush()]); + return Promise.all([this.#container?.destroy(), this.#logger?.flush(true)]); } emit(eventName: string, ...args: any[]) { diff --git a/packages/platform/platform-log-middleware/src/middlewares/PlatformLogMiddleware.ts b/packages/platform/platform-log-middleware/src/middlewares/PlatformLogMiddleware.ts index 9ca9b2832ec..81216b42b2c 100644 --- a/packages/platform/platform-log-middleware/src/middlewares/PlatformLogMiddleware.ts +++ b/packages/platform/platform-log-middleware/src/middlewares/PlatformLogMiddleware.ts @@ -81,8 +81,6 @@ export class PlatformLogMiddleware implements MiddlewareMethods { } } } - - ctx.logger.flush(); } /**