Skip to content

Commit

Permalink
fix(di): fix issue when pushing logs after request end (#2423)
Browse files Browse the repository at this point in the history
  • Loading branch information
Romakita authored Sep 2, 2023
1 parent 77a8649 commit 7e26465
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/di/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
};
6 changes: 5 additions & 1 deletion packages/di/src/node/domain/ContextLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,18 @@ 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);
});

this.#stack = [];
}

if (stream) {
this.maxStackSize = 0;
}
}

public isLevelEnabled(otherLevel: string | LogLevel) {
Expand Down
2 changes: 1 addition & 1 deletion packages/di/src/node/domain/DIContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export class DIContext {
}

destroy(): Promise<any> {
return Promise.all([this.#container?.destroy(), this.#logger?.flush()]);
return Promise.all([this.#container?.destroy(), this.#logger?.flush(true)]);
}

emit(eventName: string, ...args: any[]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,6 @@ export class PlatformLogMiddleware implements MiddlewareMethods {
}
}
}

ctx.logger.flush();
}

/**
Expand Down

0 comments on commit 7e26465

Please sign in to comment.